Interactive Sed script

I need to write a script that uses a command line argument as part of the sed command. It will be easier to show:
#Script
sed -n '/$1/ p' file.  Wat do I use as a delimiter for the $1 argument?
sdickensAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tel2Commented:
sdickens,

I don't think you need to delimit the argument (not in your example above anyway), but if you need to, try putting ${1} instead of $1.

NOTE: If you want your example above to work, you might want to:
1. Remove the "-n" so you get output.
2. Add a "/" after the "p" so the replacement string is delimitted.

Let me know how you get on.

PS: What's an example were you need to delimit the argument?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ahoffmannCommented:
tel2, did you get used to sdickens' example?
sdickens, is your example from within a script?
0
tel2Commented:
ahoffmann,
What do you mean by "get used to"?  Are you asking if I understand it, or what?
0
mliberiCommented:
If you put the '$1' argument inside a single apices delimited string the shell will not expand it just before calling sed.

modify your command as follows:
sed -n "/$1/p" file

so that the shell expands $1 with it's actual value before calling sed.

enjoy.
0
MoondancerCommented:
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  Or if you are an EE Pro user, click the link below to select open items for your Member ID using Power Search:
http://www.experts-exchange.com/jsp/qPowerSearch.jsp.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.