arksdf
arksdf

Reputation: 431

awk - Print output between quotes

how can I print the result of awk inside double quotes? like this:

du Screenshot*.png | awk '{print $2}' 

result that I get:

Screenshot_20200404_180903.png
Screenshot_20200404_181044.png
Screenshot_20200404_181057.png
Screenshot_20200404_181116.png

result that I want:

"Screenshot_20200404_180903.png"
"Screenshot_20200404_181044.png"
"Screenshot_20200404_181057.png"
"Screenshot_20200404_181116.png"

Upvotes: 1

Views: 1262

Answers (1)

gildux
gildux

Reputation: 564

Yes, try this:

ls Screenshot*.png | awk '{print "\""$2"\""}'

Explanation:

AWK print statement output the following arguments that are: variables content (e.g. $foo if you have a variable named "foo", $2 for the second field of current record...) and litterals (i.e. strings and numbers...) and some special symbols like coma (to insert the output field separator.) Note that the arguments can/should have space between them (for better readability) but are concatenated in the output (hence the need to put delimitors with coma or space string.)
AWK strings are within double quotes, and can contain escaped characters with backslash. That's usefull to output tabulation (\t) and double quote itself (\") Hence the strange notation above.

Upvotes: 1

Related Questions