|
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
|
|||
|
|||
|
Hi, Input file: Code:
-13- -1er- -1xyz1- -1xz12- -2ab1- -2ab2-- -143- Code: Code:
grep '^[\-][0-9][a-z]*[0-9]\-' input.txt Wrong output: Code:
-13- -1xyz1- -2ab1- -2ab2-- Expected output: Code:
-1xyz1- -2ab1- This is what i am trying to do: 1)starts with - as first one 2) second character any number 3) third one any letter a to z 4) penultimate char - any number 5) last one is with - Thanks in advance . |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
Hi. Your description could be considered slightly ambiguous, but: Code:
$ egrep '^-[0-9][a-z]+[0-9]-$' file1 -1xyz1- -2ab1- |
| The Following User Says Thank You to Scott For This Useful Post: | ||
dragon.1431 (09-10-2010) | ||
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
Hi Scottn,
just curious, is it not possible to do it with grep / awk ? |
|
#4
|
||||
|
||||
|
He is using grep, ie. egrep is like grep -E.
|
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
And the awk is the same: Code:
$ awk '/^-[0-9][a-z]+[0-9]-$/' file1 -1xyz1- -2ab1- |
| 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 |
| regular expression at the end of grep | iga3725 | Shell Programming and Scripting | 3 | 06-11-2010 09:46 AM |
| grep and regular expression | kminkeller | Shell Programming and Scripting | 9 | 02-24-2010 12:55 AM |
| grep with regular expression | daikeyang | Shell Programming and Scripting | 6 | 03-22-2009 07:46 PM |
| regarding grep regular expression | ukatru | UNIX for Advanced & Expert Users | 2 | 10-22-2008 11:47 PM |
| grep : regular expression | RishiPahuja | Shell Programming and Scripting | 10 | 09-13-2005 12:53 AM |
|
|