INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Passing SED variable

Passing SED variable

(OP)
This is one of those things that always seems to bite me.

I have the following in my script -
sed -i '284s/"[^"]*"/"mclane.com mclane.mclaneco.com"/g' <filename>

I need to configure the command so the 284 line number can be read as $ln in case the file
gets modified and the line number that actually needs to be edited changes.

I thought the following would work but that is not the case.

sed -i "$ln s/"[^"]*"/"mclane.com mclane.mclaneco.com"/g" <filename>


Thank you for your insight and assistance.

SteveR77

I.T. where a world of choas and confusion comes down to nothing but 1s and 0s.

RE: Passing SED variable

2
Hi

That would be correct for Sed, however the shell will probably yell at you because of unterminated string :
sed -i "$ln s/"[^"]*"/"mclane.com mclane.mclaneco.com"/g" <filename>       

You can either :

CODE --> line

# escape internal double quotes
sed -i "$ln s/\"[^\"]*\"/\"mclane.com mclane.mclaneco.com\"/g" <filename>

# double quote ( or not quote ) only the variable
sed -i "$ln"' s/"[^"]*"/"mclane.com mclane.mclaneco.com"/g' <filename>
sed -i $ln' s/"[^"]*"/"mclane.com mclane.mclaneco.com"/g' <filename> 

Feherke.
feherke.ga

RE: Passing SED variable

(OP)
Feherke,

Thank you. The single, double quoting, triple single quotes is always fun to attempt to keep straight.

I went with double quoting the variable and then using the single quotes which are more sed "standard" for syntax.

Thank you once again.

SteveR77

I.T. where a world of choas and confusion comes down to nothing but 1s and 0s.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close