Post by Val KremThank you for the help I got right what I wanted to do using this
cat filename |awk '{printf "%010s\n",$1}' | sed 's/ /0/g'
cat and sed are unnecessary. AWK can do everything you are using them for.
Then show it! Here's Val's "specification":
wooledg:~$ printf 'this\nquestion\nmakes\n000000000000000\nsense\n' | awk '{printf "%010s\n",$1}' | sed 's/ /0/g'
000000this
00question
00000makes
000000000000000
00000sense
And you want to duplicate this behavior using nothing but awk, yes?
Maybe something like this:
wooledg:~$ printf 'this\nquestion\nmakes\n000000000000000\nsense\n' | awk '{s=sprintf("%010s",$1); gsub(" ","0",s); print s}'
000000this
00question
00000makes
000000000000000
00000sense
I'm not an awk guru. There may be better ways to write it.
I still don't understand the goal. Val absolutely REFUSES to shed ANY
light on the nature of these input strings, which is more annoying than I
can possibly describe, especially when the "desired" output is not useful
in any way I can imagine. They're not numbers. They're not filenames.
They're not names of people, places, animals... we don't know WHAT the
hell they are!
This also makes me suspect it's all a huge X-Y problem, and any day
now, he's going to move the goalposts. "Oh, I actually wanted to
separate the alpha part from the numeric part, and zero-pad the
numeric part, and then reassemble it! By the way, it's a patient's
medical record number from the XYZ Health System, and they're formatted
without zeroes when typed by secretaries, but I need the zero padding
when I sent the results to Epic. And duh, you don't put the zeroes
in front of the alpha part. What kind of an idiot would do that?"
(Well, no, nothing that coherent. We will NEVER get anything THAT
coherent out of this person. Obviously. Hell would freeze over first.)
(And sending medical results to Epic from bash would clearly be an
exercise in extreme masochism. Not that that would stop anyone.)
And Dennis, quoting an email requires you to indicate in some way which
parts of the message are quoted and which parts are yours. You can't
just append your own text to the other person's text. Get a proper
email program, or learn how to use the one you have.