Discussion Locked
0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
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 ?
3 replies
by gary_w
Is the newline the first newline character in the row? If so, try this in good ole vi:
:%s/^M//
: = 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).
Gary
by amit.sethia
New line character is a line break in the 137th column.
cat file_in|while read line
do
if [ "`echo$line|cut -c 137`" = "\^M" ]
then echo "`echo $line|cut -c1,136`" "`echo $line|cut -c138-`" >> new_file_in
else
echo $line >> new_file_in
fi
done
This discussion is closed to new replies.
Trending Linux posts
Sort by Trending
0 helpful
7 replies
0 helpful
6 replies
Question Locked
RE: How to fix the Docker and UFW security flaw
0 helpful
3 replies
Discussion Locked
Which Linux works best on old phone or tablet?
0 helpful
5 replies
Discussion Locked
My Job and Company
0 helpful
3 replies