-   Linux - Newbie (
-   -   Shell script to delete some lines... (

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()

7297 S/3546/1994()

7298 S/3548/1994()

7299 S/3551/1994()

7300 S/3557/1994()
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 ?


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


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.


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

All times are GMT -5. The time now is 10:57 AM.