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 :)

You have to read up on the (sometimes strange) rules about quoting and variable substitution in various shells.

Try say sed $i's/$/'$age'/g' birthday.csv Or maybe sed "${i}s/$/${age}/g" birthday.csv

sed "${i}s/$/${age}/g" birthday.csv

Worked great thanks very much :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.