Questions tagged [sed]

Sed is known as a Stream Editor in that it can carry out various filtering and/or transforming functions on standard input or on user specified files. It is commonly used to search-and-replace in text files. If your question is about text-processing, this tag is likely to be appropriate

The sed command can search for, print and edit text from some stream, such as a file or standard input. It is often used as a search-and-replace tool.

Ubuntu uses the GNU version of sed

If you are asking a question about text processing, this tag is probably appropriate. If you want to transform some text, it is usually necessary to give a clear example of what you have as input and the output you want to achieve.

Related tags:

703 questions
59
votes
2 answers

Use sed on a string variable rather than a file

I have been told it was possible, but without a single working example, that sed can read from a string variable without need for an input file. I have yet to get it to work. For general safety, I’m writing the $PATH variable to another variable,…
j0h
  • 14,825
58
votes
3 answers

Sed to delete blank spaces

Does anyone know how to use Sed to delete all blank spaces in a text file? I haven been trying to use the "d" delete command to do so, but can't seem to figure it out
Justin
  • 2,121
35
votes
1 answer

Appending to end of a line using 'sed'

I have a line that says... Fred Flintstone, Bedrock USA and I want it to look like... Fred Flintstone, Bedrock USA *** How do I append a few * to the end of the line using sed command?
Justin
  • 2,121
11
votes
3 answers

Replacing a string by a file using Sed

Lets say i have two files foo and bar. I want a replace the string "this is test" in foo with the contents of the file bar. How can i do this using a one liner sed? I have used: sed -i.bak 's/this is test/$(cat bar)\n/g' foo but the the string is…
heemayl
  • 91,753
7
votes
1 answer

Remove exact matching word using sed

I want to remove word 'foggy' from the string. It fails. Why? echo 'foggy light' | sed 's/\//g'
Josef Klimuk
  • 1,596
6
votes
1 answer

Add text to same line using sed

How can I use a variable to find a pattern and then add a text, in the same line, after that pattern? I tried this but it didn't work: sed -i "/$node_number/ i mytext" "$filepath.csv";
4
votes
5 answers

How do I replace all occourences of a symbol except the last one using sed?

For example, I got a line like this: 44567743346_567864_56788_5677_3 I want to change all the _ into :, except for the last one would change into \. The expected output is: 44567743346:567864:56788:5677\3
4
votes
1 answer

Delete the whole line starting with a special character except for the first word

I have very recently started using linux and I am almost completely oblivious on sed commands. I need to edit a file that contains a bunch of long lines starting with the common character ">" and delete the rest of this line only keeping the first…
user300245
  • 41
  • 1
  • 2
3
votes
1 answer

sed /RegEx/,~N format address

$ sed '/b/,~8 d' a-i.txt I know what it does. But, they say "a multiple of 8" for ~8. Why is it expressed as "a multiple of 8"?
Smile
  • 1,099
3
votes
1 answer

Help understanding sed command

Can anyone help me understand what this sed command does : sed -n '/\(^[^:]*[eE]xception\):.*/s//\1/p' $LOGFILE | uniq -c Does this search $LOGFILE for the words Exception or exception, count how many lines have this word and report the count? I…
3
votes
1 answer

Using -e option with sed to run sed from a script fails

My sed command works fine on the command line but when I put it in a bash script and call it with sed -e sedscript.sh I get $ sed -e sedscript.sh sed: -e expression #1, char 12: unterminated `s' command This is the sedscript.sh: $cat…
Don
  • 293
3
votes
1 answer

How to replace a line that starts with a word (and use that old line on the new line)

I have a file with many lines and I would like to replace specific lines that start with a new line but include the old line in it. See below. for example, if a line starts with (xyz is different for every line) "#EXT-1,xyz" I would like to have a…
LewHam
  • 33
3
votes
1 answer

Sed word duplication problem

I'm new to sed and trying out stuff to learn. However I'm encountering a problem I can't solve when using sed to remove duplicate words : echo "abc abc def ghi ijk ijk" | sed 's/\([a-z][a-z]*\) \1/\1/g' outputs abc def ghijk ijk and it does that…
Mr. Smith
  • 109
3
votes
2 answers

using sed to remove equals sign from a file

I am trying to use sed to remove the equals signs from this file and pipe it to a new file: I am a file to be edited. A unique file with my own words. T=h=e=r=e a=r=e i=s=s=u=e=s w=i=t=h t=h=i=s l=i=n=e I tried cat FixMeWithSed.txt | sed 's/=//' >…
Michael James
  • 275
  • 2
  • 6
  • 15
3
votes
2 answers

how to remove two forward slashes in a comment with sed

I have a configuration file and I want to replace a line containing a specific string, lets say test : file.conf aaa bbb ccc // test ddd // test My line of code is not working, I'm new to sed. sed -i `s#^//[ \t]test#test#g' Some guidance ?
1
2 3 4 5 6