Score:0

How do I underline formatted output in awk?

ni flag

I am new to awk and having a hard time figuring out how to format output with underlines. It doesn't appear to be possible to use formatting escape sequences in awk e.g. \e[4m?

Is there a way to underline "Name" "Email" and "Phone" without printing a new line of underscores?

Heres my code:

awk -F";" 'BEGIN 
           {printf "%-20s %-20s %s\n\n ", " Name", "email", " Phone "}
           {printf "%-20s %-20s %s\n ",$1,$2,$3}'
hr flag
You can use essentially the same as [How to print awk's results with different colors for different fields?](https://askubuntu.com/questions/1326271/how-to-print-awks-results-with-different-colors-for-different-fields)
carol marjara avatar
ni flag
Thank you for linking to this. My error was in trying to apply the ANSI underline sequence to "Name" etc. instead of the modifier string. Also had to replace "\e[4m " with "\033[4m" which did the trick as outlined here: https://stackoverflow.com/questions/29983248/ansi-escapes-dont-work-in-printf
hr flag
Yes, you can represent the escape character `\e` as either octal `\033` or (as I did in the linked question) hexadecimal `\x1b` - your choice
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.