Remove Carriage returns between strings in a field

Is there any way to remove carriage retuns between the records?

We have input records separated by TABS and have carriage returns as below:

123 456 789 ABC "1952.00" 678 "abcdef
ghik
lmno"

Above we have 7 fields, notice that the 7th field in the records has carriage returns and make it into records...

I need to remove the carriage returns and make it look like below:

123 456 789 ABC "1952.00" 678 "abcdef ghik lmno"

Let me know your thoughts?

Thanks,
AC

Use Awk:

{ record = record $0
  # If number of quotes is odd, continue reading record.
  if ( gsub( /"/, "&", record ) % 2 )
  { record = record " "
    next
  }
}
{ print record
  record = ""
}
 > cat file
123 456 789 ABC "1952.00" 678 "abcdef
ghik
lmno"
 > cat file | tr  \\n " " ; echo
123 456 789 ABC "1952.00" 678 "abcdef ghik lmno"

A less fancy way is:

for i in `cat file`
   do echo -n "$i "
done
echo

In Solaris replace echo with /usr/ucb/echo

Why use cat when cat is a do-nothing program here? Why not

tr  \\n " " <file

What if the file contains more than one record?

Record1 "1952.00" 678 "abcdef
ghik
lmno"
Record2 "1952.00" 678 "abcdef
ghik
lmno"

Wouldn't the output be

Record1 "1952.00" 678 "abcdef ghik lmno" Record2 "1952.00" 678 "abcdef ghik mno"

Good points.

Thanks a lot for all your inputs. The below code soles the problem with the example I had given. When the data had double quotes...

{ record = record $0
# If number of quotes is odd, continue reading record.
if ( gsub( /"/, "&", record ) % 2 )
{ record = record " "
next
}
}
{ print record
record = ""
}

The tr \\n " " removes all the new lines and forms a one big record. I don't want this to happen.

Thanks again everybody.

AC

One more thing.. Could you tell me what it does excatly....
especially if ( gsub( /"/, "&", record ) % 2 )

Thanks in advance.

AC

We know that the record is incomplete if the number of quotes it contains isn't even. We use gsub to count the number of quotes in the line:
gsub( /"/, "&" )
replaces each quote with a quote (the & stands for whatever was matched by the regular expression) and returns the number of substitutions made. If that number is odd, i.e., if dividing by 2 gives a non-zero remainder, then the record is incomplete. So we tack on a space and jump back to the top of the input loop.

hi all,

i have csv file with three comma separated columns
i/p file
First_Name, Address, Last_Name
XXX, "456 New albany \n newyork, Unitedstates \n 45322-33", YYY\n
ZZZ, "654 rifle park \n toronto, canada \n 43L-w3b", RRR\n

is there any way i can remove \n (newline) from the second column
between the two double quotes"..."

u didn't mention where you are calling the file in the script
all u said is record?
what do u mean by record !
can u send me the whole script please , i have the similar situation

The above script works fine for some record. I recently got awk error something like more than 199 fields... I'm currently using awk -f {abovescript}.awk on HP-UX 11.0 box...

Is there any way to overcome the above awk error?

Thanks in advance.