awk - Replacing newline character in a field in csv file -
i have csv file
165 columns , have problem. need replace \r\n
characters blank space columns not end of line record separator.
input:
001|baker st. london|3|4|7 002|penny lane liverpool|88|5|7
output:
001|baker st. london|3|4|7 002|penny lane liverpool|88|5|7
i using windows script open using unxtools (gawk, sed, tr)
or whatever it's needed.
so need group multi line fields. in case, let's manually store string until "big enough", is, until has enough fields know record complete:
awk -f"|" -v fields=5 '{f+=nf; str=(str?str ofs:"") $0} f>=fields{print str; str=""; f=0}' file
with -v fields=5
indicate how many fields proper line should contain. then, keep storing data in str
variable until has @ least fields
fields.
note working windows file. work in unix, first convert format using dos2unix file
. convert \r\n
\n
.
test
$ awk -f"|" -v fields=5 '{f+=nf; str=(str?str ofs:"") $0} f>=fields{print str; str=""; f=0}' file 001|baker st. london|3|4|7 002|penny lane liverpool|88|5|7
(old version, when looked needed remove literal \r\n
)
just make sure appears after \r\n
, end of line not matched:
$ sed -r 's/\\r\\n(.)/ \1/g' file 001|baker st. london|3|4|7\r\n 002|penny lane liverpool|88|5|7\r\n
this looks \r\n
plus thing , prints other thing after space.
Comments
Post a Comment