Friday, December 7, 2012
11:32 AM

Add new Line while Appending two files in Linux

If two files containing following content
file1:
1
2
file2:
3
4

After append : cat file2>>file1 
output in file1:
1
23
4

to Add new Line while Appending two files
Command : sed -i -e '$a\' file2 | cat file2 >> file1

From Above
sed -i -e '$a\' file2
This adds \n at the end of the file only if it doesn't already end in a newline. So if you run it twice it will not add another newline.

0 comments:

Post a Comment