gnu-parallelquotingsingle-quotes

Remove auto single quotes in GNU Parallel


I'm running this command, to change "Text to replace" in text files with the basename the text file:

parallel --dry-run sed -i \"s/Text to replace/{.}/\" {} ::: *.txt

However, when there is a space in the text file's filename, Parallel inserts a single quote:

sed -i "s/Text to replace/'with space'/" 'with space.txt'

And without spaces, Parallel doesn't insert a single quote:

sed -i "s/Text to replace/without_space/" filename_without.txt

Is there a way to make Parallel never automatically insert single quotes?


Solution

  • GNU Parallel shell quotes replacement strings. This is normally what you want:

    touch "important_file.txt" "not important_file.txt"
    parallel rm ::: not*
    # Removes 'not important_file.txt' and not: not important_file.txt
    

    However, in a few cases you really want full control of the replacement string. In this case you can tell GNU Parallel to unquote the string:

    parallel --dryrun echo {=uq=} ::: *
    

    uq() is a perl function, so you can do other stuff in the {==}:

    parallel --dryrun echo '{= s/a/b/; uq(); =}' ::: *