
Hi Markus, in principle it works, you can put all stuff in one line and run it between single quotes as a awk command line. There is a little script doing this for you: cat $my_awk_file | awk '{if (NR>1) for (i=1; i<=NF; i++) printf $i" "}' In general it works, however, you have to escape the single quotes _inside_ the script. "'" has to be written as "'"'"'" Well, that syntax hurts;-) especially if you want to write a awk line that processes an awk script to get an awk line.. And than you get: cat $my_awk_file | \ awk -F"'" '{for (i=1; i<NF; i++) printf $i"'"'"'""\"""'"'"'""\"""'"'"'"; print $NF}' | \ awk '{if (NR>1) for (i=1; i<=NF; i++) printf $i" "}' The appearing output as a command line to do what the awk script does: cat $my_file | awk '{ if ($1=="Repo-name") {printf "'"'"'"; for (i=3; i<NF; i++) printf $i" "; printf $NF"'"'"' "} if ($1=="Repo-baseurl") { url=1; comma=match($NF,","); if (comma) out=substr($NF,1,comma-1); else out=$NF; printf "'"'"'"out"'"'"' "; } else { if (url==1) { if ($1==":") { comma=match($NF,","); if (comma) out=substr($NF,1,comma-1); else out=$NF; printf "'"'"'"out"'"'"' "; } else {url=0; print "";} } } }' Well, that's all in one line now - but who can read that? Feel free to use whatever you like;-) Regards Peter Quoting "Marcus Furlong" <furlongm@gmail.com>:
On Thu, Nov 17, 2011 at 12:36, Peter Ross <Peter.Ross@bogen.in-berlin.de> wrote:
Hi Marcus,
first I had an error (spot the url=1 instead of url==1 condition?) so it did not work that well for multiple appearences.
However, this one should do:
#!/usr/bin/awk -f { if ($1=="Repo-name") { printf "'"; for (i=3; i<NF; i++) printf $i" "; printf $NF"' "; } if ($1=="Repo-baseurl") { url=1; comma=match($NF,","); if (comma) out=substr($NF,1,comma-1); else out=$NF; printf "'"out"' "; } else { if (url==1) { if ($1==":") { comma=match($NF,","); if (comma) out=substr($NF,1,comma-1); else out=$NF; printf "'"out"' "; } else {url=0; print "";} } } }
I made it a bit more "C-like" in appearance but the logic is the same.
Thanks Peter, this one works perfectly! Is it possible to run the above on the command line so I can process through the pipeline without an external awk script? I've been playing with the formatting but keep getting "unexpected newline or end of string" along with plenty of syntax errors...
Marcus. -- Marcus Furlong