Thursday 6 December 2012

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.

Share This!



No comments:

Post a Comment

Here We Write The Problems we face at different situations and Solutions to those problems.