0

I am looking over a bash file and I don't know what the following lines do:

sed s/
//g < setenv.sh > setenv.sh2

When running the script, I always get an error on line 2:

//g: No such file or directory

So what it his trying to do here ?

PersianGulf
  • 2,845
  • 6
  • 47
  • 67
Adrian
  • 19,440
  • 34
  • 112
  • 219

3 Answers3

4

It looks like that's a broken attempt to remove newlines from a file.

sed s/<enter|return>//g

Of course, it won't work – sed is newline aware. Just joining the lines probably won't do what you want either, unless there's an invisible character between the first slash and the line break. Otherwise you'd end up with

sed s///g

What you should do instead is identify which character (newline, carriage return, both?) you want, and use tr -d

tr -d $'\n' < file > file.nonewlines
tr -d $'\r' < file > file.nocarriagereturns
tr -d $'\r\n' < file > file.nocrlfs
kojiro
  • 74,557
  • 19
  • 143
  • 201
0

missing quote or double quote around the action and an escape of the new line also this is certainly part of a bigger script where working buffer could have more than 1 line in it. It is maybe coming from a print copy of a script

sed '#other action before this like H or N
s/\
//g' < setenv.sh > setenv.sh2

for the g it mean every occurence of the substitution (s///) but error is coming from the wrong first pattern (escaped enter)

NeronLeVelu
  • 9,908
  • 1
  • 23
  • 43
0

The /g flag cause not only the first occurence in each line to be replaced but all.

echo "ggg" | sed -e 's/g/j/' 
# jgg
echo "ggg" | sed -e 's/g/j/g'
# jjj
MUY Belgium
  • 2,330
  • 4
  • 30
  • 46