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?

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.