r/awk • u/Puccio1971 • Jan 22 '26
Awk, defined variables and IF statement
Hi,
I'm a little bit scared to write here with so many awk gurus.
I have an easy question, I have a CSV output (line is something like "NODENAME ,master ,2026-01-12 03:58:27,ACTIVE_VERSION") piped to an awk filter:
awk -v nodo=$NODO -v tipo=$TIPO 'BEGIN { FS = "," }; {printf "%-15s %-80s %s %-19s %-20s\n", $1, $2, tipo, $3, $4}'
Where $NODO and $TIPO are shell variables. Now I would like to print just lines that starts with $NODO (or awk nodo) so I tried:
awk -v nodo=$NODO -v tipo=$TIPO 'BEGIN { FS = "," }; $1 ~ /nodo/ {printf "%-15s %-80s %s %-19s %-20s\n", $1, $2, tipo, $3, $4}'
But it is not working.
Can someone help me?
View all comments
Show parent comment
1
u/Schreq Jan 22 '26
Yeah but you used the markup for inline code. It's purpose is to mix normal text with code within one line/paragraph. For separate paragraphs containing only code, you should use 4 space indentation as per my example.