Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get sed to read from standard input? [duplicate]

Tags:

linux

bash

shell

I am trying

grep searchterm myfile.csv | sed 's/replaceme/withthis/g' 

and getting

unknown option to `s' 

What am I doing wrong?

Edit:

As per the comments the code is actually correct. My full code resembled something like the following

grep searchterm myfile.csv | sed 's/replaceme/withthis/g' # my comment 

And it appears that for some reason my comment was being fed as input into sed. Very strange.

like image 658
deltanovember Avatar asked Apr 02 '12 22:04

deltanovember


People also ask

How do you stop standard input?

press CTRL-D to end your input. This is the right answer. Ctrl-D is the canonical way to terminate keyboard stdin in any shell command.

Which of the following is used to read a line from the standard input in bash?

We have been using read “read –r” while reading from another file as other than standard input. On the other hand, using “-u” as bash-specific, the standard output from the user in the terminal. Here, the “name” is the text or content of the file “script.sh”. The option “-p” is used to “read”.

Which of the following is used to read a line from the standard input in Linux?

Bash read Built-in read is a bash built-in command that reads a line from the standard input (or from the file descriptor) and split the line into words.


2 Answers

use the --expression option

grep searchterm myfile.csv | sed --expression='s/replaceme/withthis/g' 
like image 110
Ben Davis Avatar answered Oct 20 '22 18:10

Ben Davis


use "-e" to specify the sed-expression

cat input.txt | sed -e 's/foo/bar/g' 
like image 31
umläute Avatar answered Oct 20 '22 20:10

umläute