sed and awk - my two old friends
Writing some shell scripts I needed to do some a little fancier variable substitution than the standard shell offers. The heavyweight solution would be to write a perl one-liner, but this is, well…, heavyweight?
Here’s a couple of patterns I used:
--parameter=$(sed -re 's/ /,/g' -e 's/(^|,)/\1file:/g' <<<$INPUT)- replaces spaces with commas and prependsfileto every file.--parameter=$(awk '{split($0, a, /@/); printf "%s-?????-of-%05d", a[1], a[2]} <<<$INPUT)' - replaces --parameter=$(awk '{sub(/.*:/, ""); print $0}' <<<$INPUT)- removes everything before the colon.
file@5 with file-?????-of-00005