LinuxQuestions.org
Register a domain and help support LQ
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 09-12-2012, 08:08 AM   #1
cjagdish69
Member
 
Registered: Oct 2003
Location: Bombay,Maharashtra,India
Posts: 60

Rep: Reputation: 15
Shell script to delete some lines...


I have a text file as follows :


7294 S/3529/1994()


7295 S/3540/1994()


7296 S/3545/1994()
A.


7297 S/3546/1994()


7298 S/3548/1994()
","


7299 S/3551/1994()
&


7300 S/3557/1994()
CHOL
The first column is the serial no.

I want to delete all the lines which does not start with the serial number.

How can it be done using shell script or sed ?

Jagdish
 
Old 09-12-2012, 09:11 AM   #2
SecretCode
Member
 
Registered: Apr 2011
Location: UK
Distribution: Kubuntu 11.10
Posts: 562

Rep: Reputation: 102Reputation: 102
Assuming your serial number is exactly 4 digits - if it isn't, you'll need to explain the rules

Code:
sed -r '/^[0-9]{4}/!d' yourfile
 
Old 09-12-2012, 11:10 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
Or use the same regex, but instead extract all the wanted lines with grep.

Code:
grep -E '^[0-9]{4}' infile >outfile
 
  


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
[awk script] Help me delete lines in a file using script ? sieukid Programming 5 03-20-2012 01:23 PM
delete multiple lines from file using shell script mech123 Linux - Newbie 4 06-09-2010 04:04 AM
How to delete lines and insert another line in some xml files using a shell script? luananeko Linux - Newbie 1 07-20-2009 09:53 PM
Need a bash shell script which will delete lines from file scjohnie Linux - Newbie 1 09-13-2008 08:51 PM
Shell Script: Delete lines til string found or until particular string. bhargav_crd Linux - General 3 12-20-2007 11:14 PM


All times are GMT -5. The time now is 03:18 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