|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
how to delete the line if the first letter is a single digit
Hi, I'm trying to acheive the following, I have a dat file in which i have several addresses, If the address starts with a single digit then i have to delete the line, if it starts with 2 or more digits then i have to keep the line Here is a sample of my file: Code:
377 CARRER DE LA DIPUTACIÓ BARCELONA CATALUNYA 08013 ESP 77 GREEN STREET HIGH WYCOMBE BUCKINGHAMSHIRE HP11 2 GBR 2 KREUZWEG ERSIGEN BERN 3423 CHE 3 MUNCHPLATZ 10. BEZIRK-FAVORITEN WIEN 1100 AUT Here is what i want in my output file: Code:
377 CARRER DE LA DIPUTACIÓ BARCELONA CATALUNYA 08013 ESP 77 GREEN STREET HIGH WYCOMBE BUCKINGHAMSHIRE HP11 2 GBR I have tried the following regex: sed -e /^[0-9]/d -- this is deleting all lines. Last edited by Scott; 02-04-2012 at 02:35 PM.. Reason: Use code tags, please. |
| Sponsored Links | |
|
|
|
#3
|
||||
|
||||
|
Code:
grep -E '^[0-9]{2}' infileCode:
sed '/^[0-9][0-9]/!d' infile Code:
awk '/^[0-9]{2}/' infilewhitespace proof: Code:
awk '$1~/[0-9]{2}/' infile1039 |
|
#4
|
||||
|
||||
|
@ramky79: A little tweak to your attempt. Add space after [0-9] - "[0-9] ". Code:
sed '/^[0-9] /d' inputfile |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Using grep... Code:
grep -v "^[0-9] " infile --ahamed |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Then use [ \t] , since otherwise this will not work if the whitespace happens to be tab: Code:
sed '/^[0-9][ \t]/d' inputfile Code:
grep -v "^[0-9][ \t]" infile Or to make it also tolerant to whitespace at the beginning - like the last awk example - use ^[ \t]*[0-9][ \t] |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to add single digit in front of the word and line in the file. | krbala1985 | Shell Programming and Scripting | 6 | 04-14-2011 12:26 PM |
| single line command to delete a 6 months old file | wtolentino | UNIX for Dummies Questions & Answers | 6 | 07-29-2009 02:23 PM |
| Single digit date to double digit date. | villain41 | Shell Programming and Scripting | 3 | 02-02-2009 03:53 AM |
| delete a single space in a line | Satyak | Shell Programming and Scripting | 1 | 10-31-2008 07:01 AM |
| Append 0 for single digit entered from command line | namishtiwari | UNIX for Dummies Questions & Answers | 2 | 08-24-2007 05:01 AM |
|
|