sed
linux command:sed
stands for Stream Editor
. As its name advertise it works on stream of text (input file, input pipleline).General command executation:
sed REGEX INPUTFILE
For instance if you want to replace
hi
with bye
in hibye.txt file:sed 's/hi/bye/' hibye.txt
It will print the result into standard output (console). If you want to put the output in a file:
sed 's/hi/bye/' hibye.txt > output.txt
Instead of
INPUTFILE
we can put -
which then reads from standard input:cat hibye.txt | sed 's/hi/bye/' -
Now if you want to put the output in a file:
cat hibye.txt | sed 's/hi/bye/' - > output.txt
As until now you have seen,
sed
command writes output to standard output, if you want to write the result to the file itself, use -i
as below:sed -i 's/hi/bye' hibye.txt
So in the above command the result will be written to
hibye.txt
itself.#linux #sed #regex