Thanks for the replies to my previous message - which led to this one.
I have an awk statement that looks like this:
awk '{print "cp", $1, "/directory/STR" $2}' infile
which copies $1 (the file) to $2 (the directory). The trouble is, the
value of $2 needs to be 4 digits, with leading zeros, while the infile
has stripped off the leading zeros. For example, if the file looks
like:
filename 8
filename 13
filename 5
Then the file is copied to /directory/STR8, /directory/STR13, and
/directory/STR5.
I need to find a way to pad the value of $2 with leading zeros, so in
the above example the filename would be copied to
/directory/STR0008
/directory/STR0013
etc.
I've been round and round with trying different variations of echo and
printf, and just can't seem to get it right - I may have a backtick or
quote problem, but I'm so new to awk and scripting in general, I don't
have a clue.
Any help would be appreciated - thanks!