Sed

De WikiSys
Aller à : navigation, rechercher
echo "abc def " | sed 's/\([a-zA-Z]*\) \([a-zA-Z]*\) / \2 \1 /' 
def abc 
echo 'Trail_v.value_of_key_off_trail tra_cat "category" ' | sed 's/Trail_v.value_of_key_off_trail tra_\([a-zA-Z]*\) "\([a-zA-Z]*\)" / "\2" tra_\1 /'
"category" tra_cat

skip all \n

echo $(cat file)

insert Line Feed / Carriage Return

echo "abcd" | sed 's/abcd/ab\ncd/' 
ab
cd

sed with \r

sed 's/abcd/ab\rcd' 
echo "abcd" | sed 's/abcd/ab\rcd/' 

cd

insert line

sed '/PATTERN/ i <LINE-TO-BE-ADDED>' FILE.txt


sed "/Current : /a $line" FILE.txt

insert file

after a line having PATTERN :

sed '/PATTERN/ r inserted_file '  file > new_file
sed '/Needs/ r n' < some_file.ml > o
include "file" after "Author" and delete line Author
cat sed_include.sh 
#!/bin/sh
sed '/Author/ {      

r file d

}'
sed_include.sh < t.ml    
file replaces Author line

delete ctrl + M

sed -ie 's/[ctrl+v][ctrl+m]//' mon_fichier.txt

delete line

sed /that/d file

&

 echo "123 abc" | sed -r 's/[0-9]+/& &/'
 123 123 abc

sed -r

 echo "C3.2.1 " | sed -r 's/[A-C]([1-6])?(\.[1-6])*/WW/g'
 WW

 echo "C3.2.1 " | sed -r '/^[A-C]/ s/[A-C]([1-6])+(\.[1-6])*/WW/g'
 echo "ab@C3.2.1 " | sed -r 's/@[A-C]([1-6])+(\.[1-6])*/@WW/g'