LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-30-2009, 07:14 AM   #1
lothario
Member
 
Registered: Apr 2004
Posts: 340

Rep: Reputation: 30
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
 
Old 08-30-2009, 07:18 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to duplicate rows of text from one file to another? guest Programming 1 04-25-2009 08:14 AM
Print only specific rows in a text file Mike_V Programming 3 04-24-2009 07:18 PM
Parsing rows and column data from a file using perl dav_y2k Programming 1 10-08-2006 11:57 AM
text data conversion: rows into columns frankie_DJ Programming 6 06-03-2006 06:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration