I have two files with no line break at the end of the file. So when I call "cat file1 file2", the last line of file1 and the first line of file2 share a line. I need a command that will output the files correctly. I can't change the files.
Asked
Active
Viewed 57 times
4 Answers
3
Assuming your files are by themselves in the pwd:
for i in *; do cat "$i" && echo ""; done
Otherwise, you will need to create an array:
files=( "file0" "file1" "file2" )
for i in "${files[@]}"; do cat "$i" && echo ""; done

Jonathan Leffler
- 730,956
- 141
- 904
- 1,278

Martin Konecny
- 57,827
- 19
- 139
- 159
2
Simply use awk:
awk 1 file1 file2

konsolebox
- 72,135
- 12
- 99
- 105
-
or `sed '' file1 file2`. – jaypal singh Aug 03 '14 at 05:34
-
or `sed b file1 file2`. – Cyrus Aug 03 '14 at 06:05
2
You can very simply add a newline
after file 1
and before file 2
with:
$ cat f1 <(echo "") f2
Example:
$ printf "line1\nline2" > f1
$ printf "line3\nline4" > f2
$ cat f1 f2
line1
line2line3
line4
With fix:
$ cat f1 <(echo "") f2
line1
line2
line3
line4

David C. Rankin
- 81,885
- 6
- 58
- 85
0
Well, A Simple idea would be to create a 3rd file with an empty line or 2 and add it in the middle....

Dani
- 14,639
- 11
- 62
- 110