LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   remove no data rows from a text file (https://www.linuxquestions.org/questions/linux-newbie-8/remove-no-data-rows-from-a-text-file-751241/)

lothario 08-30-2009 07:14 AM

remove no data rows from a text file
 
We have very large data files that looks like this:
"2009"
0
"schedule"
"4874786142354"
0
"reduce"
"lmjdnjg0479"
15
0
0


Using a bash script, how do I remove the lines with the 0 in it?
So that I get:
"2009"
"schedule"
"4874786142354"
"reduce"
"lmjdnjg0479"
15

colucix 08-30-2009 07:18 AM

Just delete them using sed. If the lines contain 0 and nothing else (spaces, tabs, control-characters) this should work:
Code:

sed -i.bck '/^0$/d' file
the -i.bck serves to edit the file in place, making a backup copy renamed with the specified suffix.


All times are GMT -5. The time now is 04:16 PM.