1

Not a duplicate question, as I am asking for awk specifically.

I have the following command to convert everything to lowercase, and then reprint out substrings in a certain order.

cat words |tr '[:upper:]' '[:lower:]' |awk '{ print substr($1,1,1)$2."texttoappend"}'

It works perfectly, but I can't help but think it would be cleaner if I could do it all within awk. Is this possible?

1 Answers1

2

If you want everything to be in lower text, this should work

echo FIELD1 FIELD2 | awk '{print tolower(substr($1,1,1)$2".""TextToAppend")}'

output is ffield2.texttoappend

If you want texttoappend as it is, this should work

echo FIELD1 FIELD2 | awk '{print tolower(substr($1,1,1)$2)".""TextToAppend"}'

output is ffield2.TextToAppend

don_crissti
  • 82,805