LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell script to delete some lines... (http://www.linuxquestions.org/questions/linux-newbie-8/shell-script-to-delete-some-lines-4175426868/)

cjagdish69 09-12-2012 08:08 AM

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

SecretCode 09-12-2012 09:11 AM

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

David the H. 09-12-2012 11:10 AM

Or use the same regex, but instead extract all the wanted lines with grep.

Code:

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


All times are GMT -5. The time now is 03:48 AM.