A way to delete specific lines

Hi all,

I hope an expert tells me that there is a way to get ride of the certain lines in my files which have no specific string on them but fixed length.
It's the original pattern:

"2010-07-26","2010","07","26","*","26.90","","13.10","","20.00","","0.00","","2.00","","","M","","M","0.60","","","","0.00","","0.00",""
"2010-07-27","2010","07","27","*","26.80","","15.30","","21.10","","0.00","","3.10","","","M","","M","0.90","","","","0.00","","0.00",""
"2010-07-28","2010","07","29","*","","","","","","","","","","","","","","","","","","","","","",""
"2010-07-29","2010","07","30","*","","","","","","","","","","","","","","","","","","","","","",""
"2010-07-30","2010","07","31","*","","","","","","","","","","","","","","","","","","","","","",""
"2010-07-31","2010","08","06","*","25.40","","12.20","","18.80","","0.00","","0.80","","","M","","M","0.00","","","","0.00","","0.00",""
"2010-08-01","2010","08","07","*","24.10","","9.80","","17.00","","1.00","","0.00","","","M","","M","0.00","","","","0.00","","0.00",""
"2010-08-02","2010","08","01","*","","","","","","","","","","","","","","","","","","","","","",""
"2010-08-03","2010","08","02","*","","","","","","","","","","","","","","","","","","","","","",""
"2010-08-04","2010","07","28","*","30.10","E","17.30","E","23.70","E","0.00","E","5.70","E","","M","","M","6.90","E","","","","M","","M"

I'd like to have this:

"2010-07-26","2010","07","26","*","26.90","","13.10","","20.00","","0.00","","2.00","","","M","","M","0.60","","","","0.00","","0.00",""
"2010-07-27","2010","07","27","*","26.80","","15.30","","21.10","","0.00","","3.10","","","M","","M","0.90","","","","0.00","","0.00",""
"2010-07-31","2010","08","06","*","25.40","","12.20","","18.80","","0.00","","0.80","","","M","","M","0.00","","","","0.00","","0.00",""
"2010-08-01","2010","08","07","*","24.10","","9.80","","17.00","","1.00","","0.00","","","M","","M","0.00","","","","0.00","","0.00",""
"2010-08-04","2010","07","28","*","30.10","E","17.30","E","23.70","E","0.00","E","5.70","E","","M","","M","6.90","E","","","","M","","M"

Thank you in advance.

Your question is somewhat vague. Not all of the lines you print are of the same length:

$ awk '{print length}' file1
136
136
99
99
99
136
135
99
99
136
$ awk 'length == 136' file1               
"2010-07-26","2010","07","26","*","26.90","","13.10","","20.00","","0.00","","2.00","","","M","","M","0.60","","","","0.00","","0.00",""
"2010-07-27","2010","07","27","*","26.80","","15.30","","21.10","","0.00","","3.10","","","M","","M","0.90","","","","0.00","","0.00",""
"2010-07-31","2010","08","06","*","25.40","","12.20","","18.80","","0.00","","0.80","","","M","","M","0.00","","","","0.00","","0.00",""
"2010-08-04","2010","07","28","*","30.10","E","17.30","E","23.70","E","0.00","E","5.70","E","","M","","M","6.90","E","","","","M","","M"

136, as far as fixed-length, gives the closest match.

awk -F, '$6!="\"\"" ' infile
2 Likes

That's the most incredibly presumptuous answer I could have imagined :slight_smile:

Thank you very much scottn and rdcwayx for your kind helps. Both ways deleted the undesired lines. However, I forgot to mention that my files have some headers which I like to keep them. So the way that rdcwayx suggested works perfect for me.
Thanks for being so wonderful!

And the shortest one :wink:

awk -F, '$6!="\"\"" ' infile
Hi,

A little explanation will be of great help

Thanks

If i understood correctly- In the input file the 6th column (with FS ,) of the shorter lines are- only double quotes " " whereas the longer lines has some values in 6th and the consecutive columns. So by not printing those lines whose 6th field is double-quoted we get the other longer lines.

2 Likes
awk -F'","' '$6""' infile

:wink:

---------- Post updated at 08:36 ---------- Previous update was at 08:29 ----------

grep \\. infile
1 Like
perl -i -pe 'if ( length($_) != 137 ) { s/.*\s*//; }' file