This awk
script works on the sample data:
awk '{ for (i = 1; i <= NF; i++)
if ($i ~ /^[[:alpha:]]+$/ && (i != 1 || $0 ~ /^ /))
$i = "{" $i "}"
print $0
}' data
For the given input, the output is exactly the desired output. The condition requires the word in each of the fields to be all alphabetic, and either 'not the first word, or if the line as a whole starts with a blank'. If there was an all-alpha word at the end, you could add a condition && (i != NF || $0 ~ / $/)
in the if
statement.
I used [[:alpha:]]
based on the question assuming that in your locale, ü
is valid as an alpha character. If you need only plain Latin letters plus ü
(U+00FC, LATIN SMALL LETTER U WITH DIAERESIS) and Ü
(U+00DC, LATIN CAPITAL LETTER U WITH DIAERESIS), then you can replace that character class with [a-zA-ZüÜ]
instead. Only EBCDIC might get screwed up by the use of a-zA-Z
, and you'd know if that's a problem for you. You can revise as necessary to get the characters you're interested in.