![]() |
| ||
| Using varibles within awk/sed commands 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 :) |
| ||
| Re: Using varibles within awk/sed commands 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 |
| ||
| Re: Using varibles within awk/sed commands sed "${i}s/$/${age}/g" birthday.csvWorked great thanks very much :) |
| All times are GMT -4. The time now is 8:08 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC