user212218
user212218

Reputation:

How to add single quotes around argument in awk print statement?

For convenience, I've created an alias to svn rm all deleted files in my working copy:

alias svnrmall="svn status | grep '^\!' | awk '{print \$2}' | xargs svn rm"

This works quite well, except when the filename contains a space character.

An easy solution to the problem seems to be to have awk enclose each file path in single quotes, but I'm having difficulty figuring out how to do that.

E.g., something like this (except this results in an error: "invalid char ''' in expression"):

alias svnrmall="... | awk \"{print '\$2'}\" | ..."

Upvotes: 3

Views: 5743

Answers (1)

Ritesh
Ritesh

Reputation: 556

Use -v to define variable q and use that variable in awk

alias svnrmall="... | awk -v q="'" '{print q $2 q}' | ..."

Upvotes: 15

Related Questions