I want to concatenate the files whose name does not include "_BASE_". I thought it would be somewhere along the lines of ...
ls | grep -v _BASE_ | cat > all.txt
the cat part is what I am not getting right. Can anybody give me some idea about this?
Try this
You can ignore some files with
ls
using--ignore
option and then cat them into a file.Also you can do that without
xargs
:UPD: Dale Hagglund noticed, that filename like "Some File" will appear as two filenames, "Some" and "File". To avoid that you can use
--quoting-style=WORD
option, whenWORD
can beshell
orescape
.For example, if
--quoting-style=shell
Some File will print as 'Some File' and will be interpreted as one file.Another problem is output file could the same of one of
ls
ed files. We need to ignore it too.So answer is:
If you want to get also files from subdirectories, `find' is your friend:
It searches files in the current directory and its subdirectories, it finds only files (
-type f
), ignores files matching to wildcard pattern*_BASE_*
, ignoresall.txt
, and executescat
in the same manner asxargs
would.