-
Notifications
You must be signed in to change notification settings - Fork 0
sed
Kyle Coberly edited this page Jul 8, 2017
·
2 revisions
sed '1,5/find-me/' input_file.txtCan create a sed script with:
#!/bin/sed -f
s/find/replace/gpYou can edit something different than your match:
sed -n '/matched-text/s/old-text/new-text/g' input-file.txt
# On any line containing "matched-text", substitute "old-text" for "new-text"-
/g- global -
/p- print affected lines -
/I- case insensitive
-
-f- Reads script from file -
-n- Supress unaffected areas
-
'- Hide shell variables -
"- Expand shell variables -
()- Execute a statement -
:- Set a label -
&1- First match
-
s/- Substitute pattern -
d/- Delete pattern -
y/- Character replacement
Can contain ranges:
-
1,5s- Substitute within the first and fifth lines
-
/c- Change line -
/d- Delete line -
/i- Add line above -
/a- Add line below