General discussion


Handling CSV file in UNIX

By amit.sethia ·
I have a csv file in unix which has 140 columns (Comma separated). I want to find 'newline character' and replace with null, only in the 137th column in the whole file. Can somebody help ?

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by Gary_W In reply to Handling CSV file in UNIX

Is the newline the first newline character in the row? If so, try this in good ole vi:


: = command mode
% = run the command on all lines
s/ = Search for
ctrl&V, enter = pattern (newline control character)
// = replace with nothing, 1st occurance on a line only. To replace all occurances use //g (g=global meaning all occurances of the pattern on the line).


Collapse -

by amit.sethia In reply to Handling CSV file in UNIX

New line character is a line break in the 137th column.

Collapse -

by ghislain.levesque In reply to Handling CSV file in UNIX

cat file_in|while read line
if [ "`echo$line|cut -c 137`" = "\^M" ]
then echo "`echo $line|cut -c1,136`" "`echo $line|cut -c138-`" >> new_file_in
echo $line >> new_file_in

Related Discussions

Related Forums