injeti
June 3, 2008, 11:10am
1
Hi, I need some help in text manipulation.
I have an input file like this:
7629 "WPCW 19 - CW/AM1, WPCB 40 - FAMN/CORNER, WPCB-DT1 50 - FAMN/CORNER, "
W35AW - Various Shopping Pgms
W41CF - TBN
W47CV - TBN
WLLS-LP 49 - AM1
WATCH WPXI 11 N & WPIX 11 CW
1234 "WPCW 19 - CW/AM1, WTRF-DT2 32 - F/MY, WPCB 40 - FAMN/CORNER, "
"WKBS-DT1 46 - FAMN/CORNER, WKBS 47 - FAMN/CORNER, WPCB-DT1 50 - FAMN/CORNER"
W45BT - FAMN/CORNER
W47CV - TBN
WLLS-LP 49 - AM1
WATCH WPXI 11 N & WPIX 11 CW
WATCH WPGH 53 F & WWCP 08 F[/b]
--------------------------------------------------------------------------
Output file should be like this:
7629WPCW 19 - CW/AM1, WPCB 40 - FAMN/CORNER, WPCB-DT1 50 - FAMN/CORNER, W35AW - Various Shopping PgmsW41CF - TBN W47CV - TBN WLLS-LP 49 - AM1 WATCH WPXI 11 & WPIX 11 CW
1234WPCW 19 - CW/AM1, WTRF-DT2 32 - F/MY, WPCB 40 - FAMN/CORNER, ""WKBS-DT1 46 - FAMN/CORNER, WKBS 47 - FAMN/CORNER, WPCB-DT1 50 - FAMN/CORNER" W45BT - FAMN/CORNER W47CV - TBN WLLS-LP 49 - AM1 WATCH WPXI 11 N & WPIX 11 CW WATCH WPGH 53 F & WWCP 08 F
--------------------------------------------------------------------------
Please provide me a solution, Thanks, Injeti
nawk -v RS='' -v OFS=' ' '$1=$1' myFile
injeti
June 3, 2008, 11:29am
3
Hi thanks a lot, it worked, but it worked with 'awk' not 'nawk'
injeti
June 3, 2008, 11:32am
4
Hi, in the output file I need a new line between two lines, just like the way I have mentioned the output file to be, currently theres no new line
injeti:
Hi, in the output file I need a new line between two lines, just like the way I have mentioned the output file to be, currently theres no new line
nawk -v RS='' -v OFS=' ' '$1=$1 {print $0 "\n"}' myFile
injeti
June 3, 2008, 11:38am
6
Thanks it worked, theres shouldnt be any space between the first 4 numbers and the next letters , like 7629WPCW, currently a space is coming 7629 WPCW
I need like this 7629WPCW and removing the quotes, Thanks
?
perl -00 -ple's/^(\d{4})\s"/$1/;s/\n//g' input
injeti
June 3, 2008, 11:48am
8
Thanks for the reply, but I need it in awk, the one solution provided by the moderator was working and am looking at an update in that same awk script, thanks
nawk -v RS='' -v OFS=' ' -v qq='"' '$1=$1 {gsub(" +" qq, "");print $0 "\n"}' myFile
injeti
June 3, 2008, 11:52am
10
Its working, while joining lines can we put a comma, thanks
sure - feel free to modify!
Another one:
nawk 'END{print RS}ORS=NF?",":RS RS{sub(/ *"/,"")}1' input
And ..., what's your next requirement ?
injeti
June 3, 2008, 11:54am
13
am not sure :(, I need a comma as well removing whatever double quotes present, thanks
nawk -v RS='' -v OFS=',' -v qq='"' '$1=$1 {gsub(" +" qq, "");print $0 "\n"}' myFile
injeti
June 3, 2008, 12:00pm
15
I guess we got it wrong, I need comma only from the next line not like 1234,ABCD, when next line is joined then I need the comma and quotes removed, thanks
injeti
June 3, 2008, 12:02pm
16
Hi, thanks a lot for your response, the solution provided by the moderator is really excellent, so I want to continue that, thanks a lot for your help
injeti:
Hi, thanks a lot for your response, the solution provided by the moderator is really excellent, so I want to continue that, thanks a lot for your help
hmmmmmmm.... I don't follow.
Could post (again) a sample input and a desired output, pls.
radoulov
injeti
June 3, 2008, 12:31pm
19
yes
INPUT is :
1086 "WPCW 19 - CW/AM1, WFPT-DT3 28 - V-ME, WTRF-DT2 32 - F/MY
WATCH WPGH 53 F & WWCP 08 F
1087 "WPCW 19 - CW/AM1, WPCB 40 - FAMN/CORNER,
WATCH WPXI 11 N & WPIX 11 CW
Desired OUTPUT should be:
1086WPCW 19 - CW/AM1, WFPT-DT3 28 - V-ME, WTRF-DT2 32 - F/MY, WATCH WPGH 53 F & WWCP 08 F
1087WPCW 19 - CW/AM1, WPCB 40 - FAMN/CORNER, WATCH WPXI 11 N & WPIX 11 CW
when the next line is joined, a comma should be added and the quotes should be removed
ok, one more try:
nawk -v RS='' -v FS='' -v qq='"' '{gsub(" +" qq, ""); for(i=1;i<NF;i++) if(!match($i, ",$" )) $i=$i ",";print $0 "\n"}' myFile