0

I need a bash script to iterate on all files in directory besides one with specific names. Maybe it can be done with help of awk/sed during script execution?

Here is my script, that simply merge all file in directory to one:

 #!/bin/bash
(find $DIR_NAME -name app.gz\* | sort -rV | xargs -L1 gunzip -c 2> /dev/null || :)

How can I add some $DIR_NAME to list, and don`t iterate over them?

干猕猴桃
  • 175
  • 3
  • 14
  • Can you give an example of paths you want to include and paths you want to exclude? – Erez Ben Harush Aug 08 '19 at 11:17
  • It`s basically directory of directories in final folder are several txt files. I execute bash script like this: ``` for updir in /home/logger/??; do for dir in $updir/*; ./cat_files.sh > DB.log ``` Example: Include name: /home/logger/Andy Exclude name: /home/logger/Tim – 干猕猴桃 Aug 08 '19 at 11:24

1 Answers1

0

Put the names of the files to be excluded into a file, say "blacklist.txt", one filename per line. Then use

... | grep -F -f blacklist.txt | sort ...

to exclude them from the input to xargs.

user1934428
  • 19,864
  • 7
  • 42
  • 87
  • @user194428 Thanks! But can I do so with directory names? – 干猕猴桃 Aug 08 '19 at 11:33
  • Your `find` command outputs the path, which includes directorynames. You would only run into trouble, if a directory name happens to be the same as a file name. You can work around this if you put into `blacklist.txt` enough of the path to uniquely identify those entries which need to be blacklisted. – user1934428 Aug 08 '19 at 11:57