0

Current Sample Data

03054;server

03055;server

I am trying to comment out the lines which containing the "server" in a file, but its failing on Solaris server, as below

root@hostname:/root# sed -i '/server/s/^/#/' /tmp/reference.txt

sed: illegal option -- i

The expected output would be

#03054;server

#03055;server

Hrishi
  • 1
  • 1
  • 1
    That error message suggests the version of `sed` on your Solaris system doesn't support the `-i` option. Check the man page. If it doesn't, you'll have to do the equivalent manually (send output to a temp file, then if the `sed` command didn't error, replace the original file with the temp). Or maybe use `perl` or some other tool instead of `sed`. – Gordon Davisson Aug 23 '23 at 09:41
  • You have an answer here: https://stackoverflow.com/questions/56876657/how-to-use-sed-i-in-solaris – Pierre François Aug 23 '23 at 09:41
  • you can do without sed if it is too troublesome on some exotit platform: awk '$0 ~ /.*server.*/ {printf("#%s\n",$0); next;}; {print}' a.txt but also awk might not be the standard awk on solaris – louigi600 Aug 23 '23 at 11:44
  • 1
    @louigi600 FYI `awk '$0 ~ /.*server.*/ {printf("#%s\n",$0); next;}; {print}' a.txt` could be written as just `awk '/server/{$0="#"$0} 1' a.txt`. On Solaris use /usr/xpg6(or 4)/bin/awk or, less desirably, nawk. – Ed Morton Aug 23 '23 at 13:19

0 Answers0