Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use sed to this substitution?

Status
Not open for further replies.

phn737

Technical User
Nov 4, 2002
31
US
I have the following line in a file:
word1 -a<follow by some number here> word2
(eg: word1 -a23 word3)

I need to change &quot;-a23&quot; to &quot;-B aa=23&quot;. I am having a hard time trying to get this done in sed. Could someone please help.

Due to other substitution in my script done by sed, I like to have the substitution above done by sed if possible.

Thank you.
 
on your exemple, in sed:
Q is a space!!
s/^\(.*\)Q-\([a-z]*[a-z]\)\([0-9]*[0-9]\)Q\(.*\)/\1 -B \2\2=\3 \4/ -----------
Ohne Intelligenz bist Du ein Fiasko,
ohne Technik ein Amateur und
ohne Herz eine Maschine.

[ Wladimir Horowitz ]
 
Thank you, jamisar, for replying to my post.

In the solution you provided, the substitution would appears to work (I have not actually try it yet) because the number, &quot;23&quot;, is known; but what if I do not know the number following the -a<###> ahead of time, how would I approach that case?

 
I tried the solution that jamisar provided, and getting this error:
sed: invalid option --B
...

There seem to be some syntax error in the solution.
 
By using the example below, this seem to be working fine for me and does what I wanted:

sed '/-a[0-9]*/s/-a/-B aa=/g'

Thank you, jamisar, for your assistance and effort.
We can end this post for now I will re-post if this give me any problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top