how to find some files and concatenate them?
eg. find src_dir -name "*.txt" | cat > dest_file
the above does not work, the content of dest_file is the path of the files,not the content of each file. thanks. |
Quote:
cat `find src_dir -name "*.txt"` > dest_file. again, I got another problem, if the result of find is empty, then the cat command will ask me to input in the terminal, how to avoid this? |
What about:
find src_dir -name "*.txt" | cat > /path to/destination/dest_file.txt OR: find src_dir -name "*.txt" | cat > less |
find . -name '*.txt' -exec cat '{}' >>new.t \;
|
Sorry, never actually tried it, but tried these:
cat /source_dir/*.txt | less Or: cat /source_dir/*.txt > /dest_dir/contents_of_cat_command.txt |
Use either -exec or -execdir of the find command or pipe the file names to xargs.
find dir/ -name "*.txt" -print0 | xargs -0 cat >cattedtext post #5 still prints out the list of files and not the contents. The less command will pause after a page of filenames is printed. |
It does print the contents, just not to a file, it prints it to standard output in such a way that you can read it as it's not flying past your eyes faster than the speed of light.
The second example prints the contents to a file called "contents_of_cat_command.txt" in the destination directory you specify. As I said, "but tried these". Edit: Then again, I did this in a Ubuntu 8.10 VM inside of Windows, the directory containing the .txt files is in another NTFS partition..../mnt/hgfs/data |
I misread the command name & was thinking of find from a previous post. Sorry Wet-Willy. Using cat directly when the files are scattered in different directories and subdirectories is difficult unless all of the files can be located with a wildcard pattern, e.g.: cat *.txt */*/*.txt.
Cat'ing together files like this is of limited use. If one is looking for a particular pattern, using grep to locate that pattern and indicate the filename containing it is more useful. |
All times are GMT -5. The time now is 12:05 PM. |