6

I need to change every occurrence of ! to : as field separators in a group file.

sed 's/!/:/g' filename > newfilename 

But I get the error /: Event not found?

Chris Seymour
  • 83,387
  • 30
  • 160
  • 202
user2358660
  • 65
  • 1
  • 3

2 Answers2

13

You are using csh so the ! is being interpreted to fix this escape the ! or just use bash:

sed 's/\!/:/g' file > outfile

With csh the ! used for command history reference and it works even inside a pair of apostrophes ' or quotation marks ", unless escaped with a backslash \.

Chris Seymour
  • 83,387
  • 30
  • 160
  • 202
1

I would verify the file existence and file permissions maybe, because the sed line works just fine:

[root@hacklab5 ~]# cat /tmp/sed.org 
dewed!Ddew!de
dewwe!ds!dewe
[root@hacklab5 ~]# sed 's/!/:/g' /tmp/sed.org 
dewed:Ddew:de
dewwe:ds:dewe
[root@hacklab5 ~]# sed 's/!/:/g' /tmp/sed.org > /tmp/sed.new
[root@hacklab5 ~]# cat /tmp/sed.new 
dewed:Ddew:de
dewwe:ds:dewe
smassey
  • 5,875
  • 24
  • 37