egrep vs. sed backreference


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting egrep vs. sed backreference
# 1  
Old 02-13-2006
egrep vs. sed backreference

My egrep outputs this:

Code:
[r0sc0@dev]$ cat html.out|sed -n '/bluetext/s/ / /gp'|egrep '[0-9]{5}'
<span class="bluetext"><b>  Lexington Park, MD 20653</b></span>


But my backreference \1 is empty. I dont understand why. Can someone clarify?

Code:
[r0sc0@dev]$ cat html.out|sed -n '/bluetext/s/&nbsp;/ /gp'|sed -n 's/.*\([0-9]{5}\).*/\1/p'

# 2  
Old 02-14-2006
got it:

Code:
cat html.out |sed -n '/bluetext/s/&nbsp;/ /gp'|sed -n -e 's/.*\([0-9]\{5\}\)<\/b>.*/\1/p'
20653

Yay.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Segregate file content using sed backreference

I have some text like EU1BTDAT:ASSGNDD filename='$SEQFILES/SUNIA.PJ008202.CARDLIB/DATECARD' EU1BTDATEST:ASSGNDD filename='$SEQFILES/SUNIA.PJ008202.CARDLIB/DATECARD' EU1CLOSEDATES:ASSGNDD filename='$SEQFILES/SUNIA.PJ008202.CARDLIB/DATECARD' EU1DATED:ASSGNDD... (8 Replies)
Discussion started by: gotamp
8 Replies

2. Shell Programming and Scripting

Help with sed backreference please

Hi, I'm using /bin/sh I would appreciate if someone could help me with SED syntax for a "simple" line. Here is where I Got to: I have these strings that are returned by my(Examples) (naturally "FullPath" is always changing don't hardcode this lol) FullPath/AAA.framework... (3 Replies)
Discussion started by: Herrick
3 Replies

3. Shell Programming and Scripting

sed and egrep question

Its really 2 questions, but both are pretty basic. Linux Redhat 1. Need to do a search and replace on a file. I need to append '--' (comment out the line) to specific lines based on a wildcard search. So if I Have GRANT SOME_ROLE_OR_USER ... I dont care what comes after that.... (2 Replies)
Discussion started by: guessingo
2 Replies

4. Shell Programming and Scripting

Regex and backreference to replace in binary file

Hello to all, I have this sed script that replaces hex strins within a binary file. As you can see, I want to replace all bytes 4X with 2X (where X could take values 0 to F). sed -e 's/\x40/\x20/g' -e 's/\x41/\x21/g' -e 's/\x42/\x22/g' -e 's/\x43/\x23/g' -e 's/\x44/\x24/g' -e... (7 Replies)
Discussion started by: Ophiuchus
7 Replies

5. Shell Programming and Scripting

Printf with backreference in ruby

Hello everybody, May you help with this, I don't know what is wrong. I want trying to print the first 4 characters as decimal and remove the "k's" from the next 7 characters. I'm trying with gsub and backrefence as shown below trying to remove the "k's" and then trying to assign to "x" the... (0 Replies)
Discussion started by: Ophiuchus
0 Replies

6. Shell Programming and Scripting

sed and egrep in perl

Hi i have a data file whcih contains the data as follows : FH332OY86|AAABBB CCCC DDDA FHLMC 30 8.000|FHLMC|3|30|8.00000000|1986|26.29164289|3.29544844|0.00000000|10.05940539|107.50704264|Mar 8 2013 12:00AM|20130311|D|DA|DAA|DAAC|201302 FH332OY87|AAABBB CCCC DDDA FHLMC 30... (9 Replies)
Discussion started by: ptappeta
9 Replies

7. Shell Programming and Scripting

sed regex backreference replacement

Hello, I want to rename multiple files and catch some points about backreference within sed and regex. Here is a part of my file list. Input: S92A.fa S92B.fa ... S96Z.fa S921.fa S922.fa ... S997.fa Note: The file names are not necessarily continuous from A~Z or 921 ~ 997, as some of the... (3 Replies)
Discussion started by: yifangt
3 Replies

8. Shell Programming and Scripting

Patterns with egrep/sed/awk?

I have an array with characters, what I want is if there are other characters in the array which I am looking for than take action that is print BAD ARRAY. So far my code just finds characters but instead I want that it should look for other characters. echo "A B C D F" | egrep -o "D | F" O/P... (5 Replies)
Discussion started by: dixits
5 Replies

9. UNIX for Dummies Questions & Answers

Help | Unix | grep | regular expression | backreference | Syntax/Logic

Hello, I'm working on learning regular expressions and what I can do with them. I'm using unix to and its programs to experiment and learn what my limitations are with them. I'm working on duplicating the regular expression: ^(.*)(\r?\n\1)+$ This is supposed to delete duplicate lines... (2 Replies)
Discussion started by: MykC
2 Replies

10. UNIX for Dummies Questions & Answers

Egrep cheat sheet anywhere? Looking for meaning of egrep -c

Hi I've been searching google and have not found what egrep -c means. Does anyone know where I can get a cheat sheet or what that -c means? thanks, Linda (2 Replies)
Discussion started by: leelm
2 Replies
Login or Register to Ask a Question