Search code examples
linuxunixsedawknawk

Problem with replace command


I have some problem with replace command.

Input file i have this

{a[$1]=a[$1]FS$2}END{for(i in a) print i,a[i]}

I want to replace with single quotes

'{a[$1]=a[$1]FS$2}END{for(i in a) print i,a[i]}'

Using the below mentioned command

find input.txt -exec sed 's/{a[$1]=a[$1]FS$2}END{for(i in a) print i,a[i]}/'{a[$1]=a[$1]FS$2}END{for(i in a) print i,a[i]}'/g' {} \;

I am getting error like this

bash: syntax error near unexpected token `('

Solution

  • Finally i found simple way to do this.

    cat input.txt sed "s/{a[$1]=a[$1]FS$2}END{for(i in a) print i,a[i]}/'{a[$1]=a[$1]FS$2}END{for(i in a) print i,a[i]}'/g"

    I hope i will helpful