sign in
|
add example
|
see also:
awk
,
ed
,
grep
,
tr
,
perlre
sed
stream editor for filtering and transforming text
[
package
|
man 1
|
usage
|
info
|
wiki
|
homepage
]
examples
configs
questions
[
new example
]
copy
91
21
echo this is a test | sed 's/a/my/'
Find and replace the string a with my
echo
sed
details
|
copy
59
13
echo this is not a test | sed -e 's/not //' -e 's/test/another test/'
Do multiple substitutions
echo
sed
details
|
copy
41
12
sed '/test/ !d' myfile
Delete all lines that do not contain the string test
sed
details
|
copy
33
13
echo test12345 | sed 's/\([a-z]*\).*/\1/'
Grab the letters from test and delete the numbers
echo
sed
details
|
copy
27
3
dd if=/dev/sda | sed 's/Marry/Sally/g' | dd of=/dev/sda
Replaces ever occurrence of Marry with Sally on the hard drive /dev/sda
dd
sed
details
|
copy
26
7
sed '3a Text to append' myfile
Append 'Text to append' after the third line
sed
details
|
copy
19
2
cat myfile.txt | sed 5q
Output the first 5 line of myfile.txt
cat
sed
details
|
copy
17
6
echo "54321 test" | sed 's/[0-9]*/& &/'
Repeat the first occurrence of any numbers
echo
sed
details
|
copy
16
3
sed '/test/ d' myfile
delete all lines on myfile that contain the string test
sed
details
|
copy
16
4
sed '1,/^$/ d' myfile
Delete all lines before first blank line
sed
details
|
copy
14
0
echo hi | sed 's/\(h\)\(i\)/\2\1/g'
swap the characters h and i
sed
echo
2 years, 4 months ago
examplenow
1 |
details
|
copy
11
2
comment lines in a file with a # (or any other character that you need)
1,$s/\(^.*$\)/#\1/
sed
vim
3 months, 2 weeks ago
kxdemon
2 |
copy
10
1
Find and replace strings in OSX
sed -i "" 's/find/replace/g' views.py
sed
osx
find
replace
1 year ago
george
3 |
copy
9
2
sed '1,3 d' myfile
Delete the first 3 lines from myfile.
sed
details
|
copy
5
0
sed -i 's/test/NewSTR/g' myfile
replace the string test with NewSTR in myfile
sed
2 years, 4 months ago
john2
0 |
details
|
copy
4
0
echo hi | sed 's/i/sometext&&&&&&&/'
copy the char i and replace it with sometextiiiiiii
sed
echo
2 years, 4 months ago
examplenow
1 |
details
|
copy
2
0
Replace all strings foo with bar
sed -i 's/foo/bar/g'
Replace all occurrences of the string foo with bar
sed
1 year, 1 month ago
examplenow
1 |
copy
0
0
zipinfo -T storage | sort -nr -k 7 | sed 15q
sed
sort
zipinfo
source
|
details
|
[
new config
]
[
ask question
]