Combined Text Files With a Delimiter to One line
I'm looking to combined multiple text files with a delimiter and their file name then erase all of the new lines and have everything on one line.
So far I can do this with two different scripts:
find -type f -name '*.txt' -print | while read filename; do echo "±±±±± $filename"; cat "$filename"; done > files.txt;
and
tr '\n' '开发者_如何学Go ' < files.txt > desiredoutput.txt
I've tried combining these two with no avail. Any suggestions?
The simplest way to combine them would be to do the tr
on each $filename
in place of cat
:
find -type f -name '*.txt' -print | while read filename do echo -n "±±±±± $filename " # The -n suppresses the \n at the end of the line. tr '\n' ' ' < "$filename" echo -n ' ' # Add a terminating delimiter done > desiredoutput.txt;
精彩评论