Help with sed backreference please


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with sed backreference please
# 1  
Old 04-11-2014
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
FullPath/BBB.framework
FullPath/CCC.framework
FullPath/DDD.framework

That I want to convert to
FullPath/AAA.framework/Versions/5/AAA
FullPath/BBB.framework/Versions/5/BBB
FullPath/CCC.framework/Versions/5/CCC
FullPath/DDD.framework/Versions/5/DDD

So basically I want to seach for "anything" after a slash up to the dot and "extract it" to copy it to the end of the string.

I'm banging my head but here is where I got to (feel like I'm near a solution)
Code:
MyFindCommand | sed -e "s/\(.*Framework\)/\1\/Versions\\/5\//"`

Any help would be really appreciated

Regards
# 2  
Old 04-11-2014
Code:
sed -r 's|\/(.*?)\..*|&/Versions/5/\1|g'

# 3  
Old 04-11-2014
You haven't said what OS you're using. The script in2nix4life supplied will work on some systems, but the -r option is not available in all versions of sed. With a standards-conforming sed, the following should work:
Code:
MyFindCommand | sed 's!\(.*/\)\(.*\)\([.]framework\)!\1\2\3/Versions/5/\2!'

# 4  
Old 04-11-2014
Thanks to both of you

Indeed, the -r wasn't available to me (on Mac OsX). Didn't know there were difference, sorry for not posting the OS.

I tried the second solution and it worked for me. Someone else gave me this solution which also worked, not sure which one is better and why but will post in case it help someone.

Code:
 sed 's#/\(.*\)/\(.*\)\.framework$#/\1/\2.framework/Versions/5/\2#g'

I prefered the one from Don Cragun as it seem neater and shorter.

Thanks a lot for your help !
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

I am learning regular expression in sed,Please help me understand the use curly bracket in sed,

I am learning SED and just following the shell scripting book, i have trouble understanding the grep and sed statement, Question : 1 __________ /opt/oracle/work/antony>cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit... (7 Replies)
Discussion started by: Antony Ankrose
7 Replies

3. 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

4. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 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 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

7. 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

8. Shell Programming and Scripting

sed over writes my original file (using sed to remove leading spaces)

Hello and thx for reading this I'm using sed to remove only the leading spaces in a file bash-280R# cat foofile some text some text some text some text some text bash-280R# bash-280R# sed 's/^ *//' foofile > foofile.use bash-280R# cat foofile.use some text some text some text... (6 Replies)
Discussion started by: laser
6 Replies

9. Shell Programming and Scripting

Issue with a sed one liner variant - sed 's/ ; /|/g' $TMP1 > $TMP

Execution of the following segment is giving the error - Script extract:- OUT=$DATADIR/sol_rsult_orphn.bcp TMP1=${OUT}_tmp1 TMP=${OUT}_tmp ( isql -w 400 $dbConnect_OPR <<EOF select convert(char(10), s.lead_id) +'|' + s.pho_loc_type, ";", s.sol_rsult_cmnt, ";", +'|'+ s.del_ind... (3 Replies)
Discussion started by: kzmatam
3 Replies

10. Shell Programming and Scripting

egrep vs. sed backreference

My egrep outputs this: $ cat html.out|sed -n '/bluetext/s/&nbsp;/ /gp'|egrep '{5}' <span class="bluetext"><b> Lexington Park, MD 20653</b></span> But my backreference \1 is empty. I dont understand why. Can someone clarify? $ cat html.out|sed -n '/bluetext/s/&nbsp;/ /gp'|sed -n... (1 Reply)
Discussion started by: r0sc0
1 Replies
Login or Register to Ask a Question