Reputation:
In awk there is toupper()
to capitalize text and gsub()
to replace text
I have seen examples of how to do each task on a file, and they work, however I am curious as to how to make a command file that when piplined with "who" will accomplish the following:
Instead of "who" outputting like such:
firstname.lastname pts/# .....[other information]
It will output like this:
Firstname, Lastname TTY # [other information removed]
How can this task be accomplished in an awk command file please?
Upvotes: 0
Views: 58
Reputation: 4855
There must be a cleaner way but this is my attempt.
echo "firstname.lastname pts/# .....[other information]" |
awk 'r=gensub(/([[:alnum:]]*)\.([[:alnum:]]*).*/, "\\1 \\2", "",$1),
split(r,a," ")
{ print toupper(substr(a[1],1,1)) substr(a[1], 2) " " toupper(substr(a[2],1,1)) substr(a[2], 2) " TTY#" }'
Upvotes: 1
Reputation: 67507
awk
to the rescue!
for any field you can do this
awk '{print toupper(substr($1,1,1)) tolower(substr($1,2,length($1)-1))'
I'm not familiar with the firstname.lastname who format (I see userid instead).
Upvotes: 1