pinpe
July 3, 2011, 10:51am
1
Hi Guys,
I need some script in removing lines containing strings like ",, ," and "rows". Retain only numbers as the output. See below for the input and output file.
INPUT FILE:
9817
9832
6285
6312
6313
6318
,, ,
6329
7078
7098
7130
7959
7983
1253
1254
1257
,, ,
,rows,selected
,, ,
DESIRED OUTPUT FILE:
9817
9832
6285
6312
6313
6318
6329
7078
7098
7130
7959
7983
1253
1254
1257
Thanks in advance.
Br,
Pinpe
sed '/,, ,/d;/rows/d' infile > outfile
awk 'int($1)' file > newfile
one more option with "SED"
sed -n '/^[0-9]/p' <file_name>
$ grep "^[0-9]\{4\}$" inputfile
9817
9832
6285
6312
6313
6318
6329
7078
7098
7130
7959
7983
1253
1254
1257
Aia
July 4, 2011, 1:57am
7
jayan_jay:
% grep -v "," input_file
It will leave empty lines behind.
However the humble grep is a strong contender.
grep '[[:digit:]]' input_file
or little more specific
grep -E '^[[:digit:]]+$' input_file