text file editing

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

Hi thanks a lot, it worked, but it worked with 'awk' not 'nawk'

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

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

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

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 ? :slight_smile:

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

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

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

OK,
I'm out :slight_smile:

hmmmmmmm.... I don't follow.
Could post (again) a sample input and a desired output, pls.

radoulov :wink:

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