Greetings Experts,
I am in AIX; I have a file generated through awk
after processing the input files. Now I need to replace or remove the new-line characters on all lines that doesn't have a ;
which is the last character on the line. I tried to use sed 's/\n/ /g'
After checking through the forums got to know that this sed will not work as it will remove the new-line character during reading the line (my assumption). As per the post in unix - How can I replace a newline (\n) using sed? - Stack Overflow, tried to use
sed -e ':a' -e 'N' -e '$!ba' -e ' /;/! s/\n/ /g'
and ended with compatibility issues. As per my understanding on sed, sed '/;/! s#\n# #g'
might resolve, but I am facing compatibility issues; After some search replaced !
with b
as sed '/;/b s#\n# #g'
and this script too faced combatibility issues.
Sample file contents:
Table1@Table2@SELECT COL1,
COL2,COL3,
COL4,COL5 FROM
TABLE1 INNER JOIN TABLE2 ON
COL1=COL21 AND COL2=COL22;
Table3@Table4@SELECT COL1,
COL2, COL3,
............
Expected output:
Table1@Table2@SELECT COL1, COL2,COL3, COL4,COL5 FROM TABLE1 INNER JOIN TABLE2 ON COL1=COL21 AND COL2=COL22;
Table3@Table4@SELECT COL1, COL2,COL3, ......;
I need the new-lines to be eliminated on all rows that doesn't contain ;
so that I can have them in a sinlge cell of the excel sheet and then split them based on @
delimited and do a lookup to get the third column.
cat output_file > excel_lookup_ready.xlsx
I have done it through awk as (not replace with space; but remove newline)
awk -F "@" { if ($0 ~ /;/) {print $0 > output_file_awk.txt} else { printf $0 > output_file_awk.txt }}' output_file.txt
cat output_file_awk.txt > excel_lookup_ready.xlsx
and the final file has the contents as what I need;
I am not able to achieve it through sed
Can you please help me..
Thank you for your time..