Hello,
I have text files to append and am able to do with cat.
cat file1 file2 >file3
and file3 works fine in UNIX (checked with vi and it looks fine) but when i open the same file in windows I see 2nd file appended as a single-line. In other words, all the lines of 2nd file appended to first file as single-line.
As I need to process that file in windows, could any please suggest how to fix this problem? perhaps I should add LR+LF every line??
I also tried line-by-line append of 2nd file to 1st file but no luck.
TIA
Yes, Windows uses CR-LF (Carriage Return - Linefeed) to terminate a line and Unix uses LF. So in order to process a windows file on Unix in most cases the CR should be removed before processing. If the result needs to be used on a Windows platform the CR needs to be added again before every LF.
To remove the CR:
tr -d '\r' < file
To add the CR:
awk 1 ORS='\r\n'
For an all in one command, resulting in a CR-LF version, try:
awk '{print $1}' FS='\r' ORS='\r\n' file1 file2 > file3
or better:
awk '{sub(/\r$/,x)}1' ORS='\r\n' file1 file2 > file3
or without converting first:
awk '{sub(/\r?$/,"\r")}1' file1 file2 > file3
In addition, you might also be interested in the unix2dos
and dos2unix
utilities.