| | |
Using varibles within awk/sed commands
![]() |
•
•
Join Date: Dec 2008
Posts: 5
Reputation:
Solved Threads: 0
Can I use my own variables within awk and sed for example:
I've written a while loop with a counter $i and I want to use the value of $i within sed and awk to edit certain lines of text within a data file.
I want to use :
sed '1s/$/texthere/g' birthday.csv
Like this:
sed '$is/$/$age/g' birthday.csv
but it only displays the name of the variable not the value it contains
$age is the result of a calculation created within the while loop that I would like to append to the end of each line.
Any help is greatly appreciated
I've written a while loop with a counter $i and I want to use the value of $i within sed and awk to edit certain lines of text within a data file.
I want to use :
sed '1s/$/texthere/g' birthday.csv
Like this:
sed '$is/$/$age/g' birthday.csv
but it only displays the name of the variable not the value it contains
$age is the result of a calculation created within the while loop that I would like to append to the end of each line.
Any help is greatly appreciated
•
•
Join Date: Dec 2008
Posts: 5
Reputation:
Solved Threads: 0
Shell Scripting Syntax (Toggle Plain Text)
sed "${i}s/$/${age}/g" birthday.csv
![]() |
Other Threads in the Shell Scripting Forum
- Previous Thread: redirect output of a CMD to file
- Next Thread: Appending to a variable
| Thread Tools | Search this Thread |






