text manipulation

Hi, i have a file like this below, and it my have n no. of lines. Moderator gave me a solution with awk, but it was working only for the first 2 lines because awk has a limitation. can anyone give me the solution, thank you
INPUT FILE:
1081 "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

1082 "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

1086 "WPCW 19 - CW/AM1, WFPT-DT3 28 - V-ME, WTRF-DT2 32 - F/MY, WPCB 40 - FAMN/CORNER,"
"WKBS-DT1 46 - FAMN/CORNER, WKBS 47 - FAMN/CORNER,"
"WPCB-DT1 50 - FAMN/CORNER, WGPT-DT3 54 - V-ME"
W35AW - Various Shopping Pgms
W47CV - TBN
WATCH WPXI 11 N & WPIX 11 CW
WATCH WPGH 53 F & WWCP 08 F

OUTPUT FILE should be like this:
1081WPCW 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 N & WPIX 11 CW

1082WPCW 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

1086WPCW 19 - CW/AM1, WFPT-DT3 28 - V-ME, WTRF-DT2 32 - F/MY, WPCB 40 - FAMN/CORNER,""WKBS-DT1 46 - FAMN/CORNER, WKBS 47 - FAMN/CORNER,""WPCB-DT1 50 - FAMN/CORNER, WGPT-DT3 54 - V-ME" W35AW - Various Shopping Pgms W47CV - TBN WATCH WPXI 11 N & WPIX 11 CWWATCH WPGH 53 F & WWCP 08 F

Perhaps I am missing something, but it appears that you are trying to eliminate single-instance <cr> <lf> between lines, but maintain when there are consecutive <cr> <lf> pairs. Thus, turn 6-7 lines or so into one long sentence.

Hi, thanks for the reply, each line should start with a number like 1081 and all the lines of text should be joined till next number 1082.

so output should be like

1081WPCW 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 N & WPIX 11 CW

1082WPCW 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

You also show a drop of:
space character
first double-quote

Also, are all starting prefixes four digits?
Is there a range of numbers? i.e. >1000 and <2000 ?

when the lines are joined, a comma can be appended or space and there is no range of numbers but always 4 digit numbers, if double quotes are removed then its good, thank you

script:

> cat conv_form
#! /bin/bash
#conv_form

ifile=file1
ofile=file9
rm $ofile 2>/dev/null
first=0

while read zf
   do
   fourc=$(echo "$zf" | cut -c1-4)
   if [ $fourc -gt 1 ] 2>/dev/null
      then
#output prior data (if any) skipping first pass thru file
         if [ $first -gt 0 ]
            then
            echo "$hold_var">>$ofile
            echo " ">>$ofile
         fi
         first=1
#clear variables
         hold_var=$(echo "$zf")
      else
         hold_var=$(echo "$hold_var" "$zf")
   fi
done <$ifile
#output prior data (if any) from where fell out of loop
echo "$hold_var">>$ofile

output:
>cat file9
1081 "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

1082 "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

1086 "WPCW 19 - CW/AM1, WFPT-DT3 28 - V-ME, WTRF-DT2 32 - F/MY, WPCB 40 - FAMN/CORNER," "WKBS-DT1 46 - FAMN/CORNER, WKBS 47 - FAMN/CORNER," "WPCB-DT1 50 - FAMN/CORNER, WGPT-DT3 54 - V-ME" W35AW - Various Shopping Pgms W47CV - TBN WATCH WPXI 11 N & WPIX 11 CW WATCH WPGH 53 F & WWCP 08 F

i will try that, the output seems to be exactly what i wanted but i dont need space & doube quotes in between 1081 "WPCW

output should be like this:
1081WPCW 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

1082WPCW 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

1086WPCW 19 - CW/AM1, WFPT-DT3 28 - V-ME, WTRF-DT2 32 - F/MY, WPCB 40 - FAMN/CORNER,WKBS-DT1 46 - FAMN/CORNER, WKBS 47 - FAMN/CORNER,WPCB-DT1 50 - FAMN/CORNER, WGPT-DT3 54 - V-ME W35AW - Various Shopping Pgms W47CV - TBN WATCH WPXI 11 N & WPIX 11 CW WATCH WPGH 53 F & WWCP 08 F

I added a couple things in the middle of the program! (commented out one line; two new lines)

> cat conv_form
#! /bin/bash
#conv_form

ifile=file1
ofile=file9
rm $ofile 2>/dev/null
first=0

while read zf
   do
   fourc=$(echo "$zf" | cut -c1-4)
   if [ $fourc -gt 1 ] 2>/dev/null
      then
#output prior data (if any) skipping first pass thru file
         if [ $first -gt 0 ]
            then
            echo "$hold_var">>$ofile
            echo " ">>$ofile
         fi
         first=1
#clear variables
#         hold_var=$(echo "$zf")
         h2=$(echo "$zf" | cut -c7-)
         hold_var=$(echo "$fourc""$h2")
      else
         hold_var=$(echo "$hold_var" "$zf")
   fi
done <$ifile
#output prior data (if any) from where fell out of loop
echo "$hold_var">>$ofile

Thanks a million, its working great!!!, could you please let me know why u used 2>/dev/null

redirects error output to "no where"
it is a common trick in programming unix

Why I used...
wanted to do a number comparison on a field
if number comparison was with a number, could do it
if numb comp was with text, it would error; so I "skip over" the error

Not very elegant, but gets the job done. In reality, I should have checked for $0 looking at return codes, blah blah....

Now that you have working code, you can make it nice and pretty!

Thank you again!!!

Hi, need a small change to the script, the output is perfect, change is

characters 1-4 should be a number - its perfect
characters 5-259 should be the remaining - its perfect
character 260 should be a new line

currently the length is not equal for all the lines, my request is to get the length of each line to 259 characters

1081WPCW 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

1082WPCW 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