Tag Info

New answers tagged

3

Your problem comes from the .*. If you only match every character that is not a ' or a " it will work: sed -ri "s/\[ ([0-9]+|(\x27|\x22)[^\x27\x22]*(\x27|\x22)) \]/[\1]/g" file.php Even better (to take possible " or ' into account): sed -ri "s/\[ ([0-9]+|(\x27|\x22)[^\2]*(\2)) \]/[\1]/g" file.php


0

The BEGIN and END loops are run before the file is processed and after it has been processed in full. The -i inplace only makes sense while a file is being processed. I can't be sure without checking the source code but it therefore seems reasonable that the BEGIN and END won't work here. As has already been suggested, that's what BEGINFILE and ENDFILE are ...


1

I think you need to use BEGINFILE instead of BEGIN and ENDFILE instead of END for the begin and end to print into the file. At least that works on cygwin. Rob@Rob-PC /cygdrive/c/tmp $ awk --version GNU Awk 4.1.1, API: 1.1 (GNU MPFR 3.1.2, GNU MP 6.0.0) Copyright (C) 1989, 1991-2014 Free Software Foundation. Rob@Rob-PC /cygdrive/c/tmp $ echo "11 aa 22 ...


1

You could use sed's w flag with either /dev/stderr, /dev/tty, /dev/fd/2 if supported on your system. E.g. with an input file like: foo first second: missing third: foo none here running sed -i '/foo/{ s//bar/g w /dev/stdout }' file outputs: bar first third: bar though file content was changed to: bar first second: missing third: bar none here So ...


0

It is possible using the w flag which writes the current pattern to a file. So by adding it to the substitute command we can report successive substitutions to a file and print it after the job is done. I also like to colorize the replaced string with grep. sed -i -e "s/From/To/gw /tmp/sed.done" file_name grep --color -e "To" /tmp/sed.done Note, that ...



Top 50 recent answers are included