Escaping special characters and & in awk

The awk command will accept escaped special characters that may be required in an output.
E.g:
Rename the following file by removing all the characters after the three character file extensions.

all_txt.zip?89&=1
backup.zip?0f3b97d464cbytrte&13856505
installer.zip?24hj4085&_23232
new_project_proj.zip?WD898f5c5csite&=108766
ls *\?* | awk -F . '{print "mv \""$0"\" " $1".zip"}'

This awk command will work for files that have common extension. To complete command and rename the files in same line, try

ls *\?* | awk -F . '{print "mv \""$0"\" " $1".zip"}' | sh<

Leave a comment

Your comment