LinuxQuestions.org
Review your favorite Linux distribution.
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, 08: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, 08:18 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 09:14 AM
Print only specific rows in a text file Mike_V Programming 3 04-24-2009 08:18 PM
Parsing rows and column data from a file using perl dav_y2k Programming 1 10-08-2006 12:57 PM
text data conversion: rows into columns frankie_DJ Programming 6 06-03-2006 07:43 AM


All times are GMT -5. The time now is 12:54 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration