I have four files:
one_file.txt
abc | def
two_file.txt
ghi | jkl
three_file.txt
m
find . -name "*file.txt" | xargs cat > full_set.txt
You can loop over each file and do a check to see if the last line ends in a new line, outputting one if it doesn't.
for file in *file.txt; do
cat "$file"
[[ $(tail -c 1 "$file") == "" ]] || echo
done > full_set.txt
You can use one line for
loop for this. The following line:
for f in *_file.txt; do (cat "${f}") >> full_set.txt; done
Yields the desired output:
$ cat full_set.txt
abc | def
mno | pqr
ghi | jkl
Also, possible duplicate.
this works for me:
for file in $(ls *file.txt) ; do cat $file ; echo ; done > full_set.txt
I hope this will help you.
Many tools will add newlines if they are missing. Try e.g.
sed '' *file.txt >full_set.txt
but this depends on your sed
version. Others to try include Awk, grep -ho '.*' file*.txt
and etc.
Try:
awk 1 *file.txt > full_set.txt
This is less efficient than a bare cat
but will add an extra \n
if missing at the end of each file