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!

using variables in a sed command

Status
Not open for further replies.

zitto

Technical User
Apr 23, 2001
1
FR
hello.
I want to use variables in a script using a sed command line. How can I do ??
Imagine there's a file containing on each line a number ("2" on the first line of the file "file1"). I want to stock the number on a given line. For example I want the number of the first line. I'd like to to something like that : sed -n '1,1p' file1 but with variables, like that :
in this case, i would be equal to 1
var1=$i,$i
var2="$var1"p
sed -n 'var2' file1
How can I do that ???
Thanx for helping me.
 
sed s/$var1/$var2/ file

this goes to stndout, so just redirect to a new file if necessary

sed s/$var1/$var2/ file > newfile
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top