3

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'}\" | ..." 
1
  • 1
    PS. no need for grep, awk can do pattern matching awk '/pattern/ {print $2}' you can do it by field too awk '$2~/pattern/ {print $2}' Commented Oct 29, 2011 at 17:19

1 Answer 1

15

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

alias svnrmall="... | awk -v q="'" '{print q $2 q}' | ..." 
Sign up to request clarification or add additional context in comments.

3 Comments

Marking this as the accepted answer because it correctly solves the problem I described. However, I am now realizing that I fell victim to The XY Problem – I would actually need to do something like awk ... {print q $2 $3 (etc.) q}.
Note for future readers: you can use $0 to select the whole line without worrying about the spaces being seperated into fields.
@Ritesh, what if I want to assign double quote instead of single quote to q? I tried q=""" but it didn't work...