0

My script takes an input file like this

user:tag:count

It takes the user, searches it on a page, and outputs the URL pointing the user. After this is done the input file should be changed to

user:tag:count:URL

The script is a while loop that starts at i=line1 and ends at the last line. So the line the loop is working on is stored in $i and the URL it got is stored in $url.

Normally i would to this with sed but i experienced problems with that if the variable contains "/". I tried it with awk:

    awk -v iv="$i" 'NR == iv' input | awk -v var="$count" '{print $0 ":"var}' 

It adds the URL at the right line, but ofc it wont help with editing input file in the way i want.

Any way to merge the 2 awk's into one so i can edit the file?

  • you can use a delimiter that won't be found in variable... for ex: # or |... echo 'foo bar' | sed 's#foo#baz#' – Sundeep Apr 11 '17 at 14:15
0

Just use sed with a non-/ delimiter. For example:

sed 's|foo|bar|'

But yes, you can also join the two awk commands:

awk -v iv="$i" -v var="$count" 'NR == iv{print $0 ":"var}' 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.