Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Awk to replace single quote

Tags:

shell

unix

awk

I want to replace all include('./ in a set of files with include('. I am trying to use awk as follows:

awk '{gsub("include\('"'"'./", "include\('"'"'", $0); print > FILENAME}' *.php

It throws me this error.

awk: (FILENAME=xyz.php FNR=1) fatal: Unmatched ( or \(: /include('.//

Any help would be appreciated.

like image 293
GeekTantra Avatar asked Dec 10 '22 17:12

GeekTantra


1 Answers

@OP, you can try using octal code for the single quote(\047) and forward slash(\057), eg

$ cat file
include('./
$ awk '{gsub(/include\(\047\.\057/ , "include(\047" ) }1' file
include('
like image 123
ghostdog74 Avatar answered Dec 28 '22 19:12

ghostdog74