The file FTP'd got few breaks and the data looks like:
ABCTOM NYMANAGER
ABCDAVE NJ
PROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCA
HR
and i want the output like:
ABCTOM NYMANAGER
ABCDAVE NJPROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCAHR
can you please help me in writing the shell script to fix these broken lines.
Every line is supposed to start with 'ABC' (key positions). Also the break is always at the 11th position and continues on the next line at 4th position..
Thanks
rubin
December 31, 2008, 2:01pm
2
$ cat file
ABCTOM NYMANAGER
ABCDAVE NJ
PROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCA
HR
awk '{ printf (NR==1) ? $0 : /^ABC/ ? RS $0 : $0 } END{ print eof }' file
Output:
ABCTOM NYMANAGER
ABCDAVE NJPROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCAHR
Or in good old sed:
command:
sed ':a;$!N;/\nABC/!s/\n//;ta;P;D' file
input:
ABCTOM NYMANAGER
ABCDAVE NJ
PROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCA
HR
output:
ABCTOM NYMANAGER
ABCDAVE NJPROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCAHR
on the file Ftp'd from the mainframe ,do we have any UNIX command to replace mainframe low and values to space or null.
i tried using tr and it doesn't work ...
Thanks
i am getting the following errors!!.. Please advise
awk '{printf (NR==1)?$0:/^'ABC'/?RS$0:$0}END{print eof}' file
awk: syntax error near line 1
awk: illegal statement near line 1
sed ':a;$!N;/\nABC/!s/\n//;ta;P;D' file
Label too long: :a;$!N;/\nABC/!s/\n//;ta;P;D
reborg
December 31, 2008, 6:09pm
6
With a classical sed, you would have to expand that to:
sed -e ':a' -e '$!N' -e '/\nABC/!s/\n//' -e 'ta' -e 'P;D'
or with a classical awk something like this:
awk 'NR>1 && /^ABC/ {printf "\n%s", $0 ; next } { printf "%s", $0 } END {print eof}'
Thank you and appreciate your help.. now i want to insert a space/null before i merge the broke record..
ABCTOM NYMANAGER
ABCDAVE NJ
PROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCA
HR
and i want the output like:
ABCTOM NYMANAGER
ABCDAVE NJ' 'PROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCA' 'HR
Thanks in advance!!
reborg
January 3, 2009, 10:23am
8
sed -e ':a' -e '$!N' -e '/\nABC/!s/\n //' -e 'ta' -e 'P;D'
awk 'NR>1 && /^ABC/ {printf "\n%s", $0 ; next } { printf " %s", $0 } END {print eof}'
Thanks for the reply. The AWK script works pretty well but the first record is pushed to one position left leaving a blank at the starting .The output looks like:
' 'ABCTOM NYMANAGER
ABCDAVE NJ' 'PROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCA' 'HR
and i want the output to be
ABCTOM NYMANAGER
ABCDAVE NJ' 'PROGRAMMER
ABCJIM CTTECHLEAD
ABCPETERCA' 'HR
from the original input file..
please suggest me how to get rid of this issue...Thanks!!