"sed" ("stream editor") is a Unix utility that parses and transforms text files.

learn more… | top users | synonyms

3
votes
3answers
3k views

sed: replace any number of occurrences of a certain pattern

Given this input: "hell -- 'this -- world --is'-- beautiful' --thanks-- we'-- are-- here" I want to replace every '--' in between single quotes with 'X-X-X' using sed. It should give the ...
2
votes
4answers
908 views

Mass Rename Files with bash

I've got a bunch of numbered files like this: file #01.ext file #02.ext file #03.ext file #04.ext file #05.ext And what I want is to make them all have three digits (two leading 0's) instead of ...
9
votes
4answers
5k views

Newlines in sed on Mac OS X

I find that \n doesn't work in sed under Mac OS X. Specifically, say I want to break the words separated by a single space into lines: # input foo bar I use, echo "foo bar" | sed 's/ /\n/' But ...
10
votes
6answers
3k views

Removing ANSI color codes from text stream

Examining the output from perl -e 'use Term::ANSIColor; print color "white"; print "ABC\n"; print color "reset";' in a text editor (e.g., vi) shows the following: ^[[37mABC ^[[0m How would one ...
7
votes
1answer
3k views

Can GNU sed (for Windows) handle Unicode? If so, is it a code-page/locale issue, or a switch?

I've been using GNU SED on and off for a couple of years now. It spins me out a bit sometimes, but it does a good job... for single-byte char sets! I now and then notice references to GNU SED being ...
3
votes
4answers
889 views

How to replace a list of strings by another list

I have a file which has (many) strings I'd like to replace, so I thought about using a simple command like: sed 's/string1/string2/g' file1 > out However, there are too many strings for that ...
3
votes
2answers
6k views

Replace special text with sed?

I'm using CMD on Windows Xp to replace special text with Sed. I'm using this command for replace special characters like $ or * : sed -i "s/\*/123/g;" 1.txt But how command must i use to replace ...
2
votes
1answer
78 views

sed: Removing \r\r before \n in a very large file

I have a corrupted disk image file (about 27 GB) in which before all \n characters \r\r was inserted. I want to remove these \r\r before all \n. I tried with awk: awk '{ sub("\r\r$", ""); print }' ...
2
votes
4answers
598 views

Bash script, string not replaced correctly with escaped $ and & characters

I have created a shell script which takes a string as input. If the string contains $ or &, then I need to replace those characters with \$ and \&. I could done that with sed command. After ...
2
votes
2answers
5k views

Sed only print matched expression

How to make sed only print the matched expression? I want to rewrite strings like "Battery 0: Charging, 44%, charging" to "Battery: 44%". I tried the following: sed -n '/\([0-9]*%\)/c Battery: \1' ...
1
vote
1answer
1k views

Using a table or script in sed to replace many special characters with escape characters?

If u want replace special characters using sed you can use different ways, but the problem is you have to replace many (100+) special characters with escape characters in many files. so it needs: ...
0
votes
2answers
472 views

Find Files With Similar Name to Folder

I'm on OS X, and I have a folder that contains a number of subfolders. There are two things I want to do. The first is to ensure that each subfolder has a file in it of the form ...