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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate Command Line with SED, from File

Status
Not open for further replies.

jmarkus

Technical User
Oct 15, 2002
124
CA
Okay, here's another "I know I can use sed, but I'm too green to know how" question:

I have a script which executes a command:
command -p/dir1 -p/dir2....-p/dirN $file

I have a file while lists dir1 to dirN called "job.lst":
/dir1
/dir2
...
/dirN

How do I use sed to read the job.lst file and insert -p/dirN for as many /dirN as there are?

Thanks,
Jeff
 
Try something like this:
Code:
pArgs=""
for dir in `cat job.lst`; do
  pArgs="$pArgs -p$dir"
done
command $pArgs $file
If you insist for using sed:
Code:
command `sed -e 's!^!-p!' job.lst` $file

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top