Hi all gurus,
Need your help in modifying the script written by tukuyomi and shipra_31
grep -v '^$' file.txt | nawk -F\| 'FNR==1{n=NF}NF<n{l=$0;getline;$0=l" "$0}1' > file_1.txt
This script is replacing all carriage return with space.
However, i need to embed another condition whereas, in 23th column, if there is a carriage return, will need to replace it with colon <:::>
Thanks in advance for your help.
Can you post a sample of your input file...
i attached the input(Input.txt) and desired output (Output.txt) file as requested.
Requirement:
-
all carriage return existed in all columns except column 23 will replace with a space (the script that i posted has done this)
-
carriage return existed in column 23 will replace with 3 colon <:::>
Thanks.
awk '{printf /^[0-9]+\|/||NR==1?RS $0:FS $0}' input.txt
Thanks rdcwayx for your code.
When i tried the code, it hits error.
nawk: syntax error at source line 1
context is
{print >>> /^[0-9]+\|/||NR== <<<
nawk: illegal statement at source line 1
fyi, OS is available for nawk.
Seems nawk don't support, change to /usr/xpg4/bin/awk
/usr/xpg4/bin/awk '{printf /^[0-9]+\|/||NR==1?RS $0:FS $0}' input.txt
Sorry for missing out something in the Output.txt
I have compensated it as attached.
The code works fine, just that in column 23, if there is a carriage return, I need to replace it with 3 colon <:::> (as Output.txt)
Thanks in advance.
/usr/xpg4/bin/awk '{printf /^[0-9]+\|/||NR==1?RS $0:":::" $0}' input.txt |/usr/xpg4/bin/awk '{for (i=1;i<=NF;i++) if (i!=23) gsub(/:::/,"",$i)}1' FS="|" OFS="|"
Thanks a lot rdcwayx. It works.
I have one last question, when i print the output to file.txt the first line in file.txt is empty row. How to avoid that?