با دستور زیر میتوان کلمات را درون فایل جایگزین نماید
sudo sed -i 's/OLD/NEW/g' FILENAME
عبارت اول یا عبارت دوم:
sudo sed -i 's/OLD|accent/NEW/g' FILENAME
حذف کاراکترهای اضافی مخفی (نظیر برنامه dos2unix)
# sed -i 's/\r//' myfile.txt
گرفتن بک آپ و بعد تغییر در فایل(بادستور زیر یک فایل با پسوند orig میسازد و سپس تغییرات را انجام میدهد-در این حالت دو فایل داریم)
sed -i'.orig' 's/this/that/gi' myfile.txt
نمای خطی که در آن کلمه word آمده باشد
sed -n '/WORD/p'
تبدیل چند تا اسپیس به یک اسپیس در متن
sed -e 's/ */ /g' فایل
حذف خطی که در آن کلمه word یافت شود(i برای این است که در فایل تغییر کند-اگر نباشد تغییر در فایل رخ نداده و فقط در خروجی مشاهده خواهد شد)
sed -i '/WORD/d' فایل
sed '1d' test
- $ sed '3d' file #Delete 3rd line
- $ sed '$d' file #Delete the last line
- $ sed '2,4d' file # Delete a range of lines(from 2nd line till 4th line)
- $ sed '2,4!d' file #Delete lines other than the specified range, line other than 2nd till 4th here-پاک کردن همه خطوط بجز خطوط ذکر شده
- $ sed '1d;$d' file #Delete the first line AND the last line of a file
- $ sed '/^L/d' file #Delete all lines beginning with a particular character: 'L'
- $ sed '/x$/d' file #Delete all lines ending with a particular character, 'x' حرف مورد نظر
- $ sed '/[xX]$/d' file #Delete all lines ending with either x or X, i.e case-insensitive delete
- $ sed '/^$/d' file #Delete all blank lines in the file
- $ sed '/^ *$/d' file #Delete all lines which are empty or which contains just some blank spaces
- $ sed '/^[A-Z]*$/d' file #Delete all lines which are entirely in capital letters:
- $ sed '/Unix/d' file # Delete the lines containing the pattern 'Unix'
- $ sed '/Unix/!d' file #Delete the lines NOT containing the pattern 'Unix'
- $ sed '/Unix\|Linux/d' file #Delete the lines containing the pattern 'Unix' OR 'Linux'
- $ sed '1,/Linux/d' file #Delete the lines starting from the 1st line till encountering the pattern 'Linux'
- $ sed '/Linux/,$d' file # Delete the lines starting from the pattern 'Linux' till the last line
- $ sed '${/AIX/d;}' file #Delete the last line ONLY if it contains the pattern 'AIX'
- $ sed '${/AIX\|HPUX/d;}' file #Delete the last line ONLY if it contains either the pattern 'AIX' or 'HPUX'
- $ sed '1,4{/Solaris/d;}' file #Delete the lines containing the pattern 'Solaris' only if it is present in the lines from 1 to 4
- $ sed '/Unix/{N;d;}' file #Delete the line containing the pattern 'Unix' and also the next line
- $ sed '/Unix/{N;s/\n.*//;}' file #Delete only the next line containing the pattern 'Unix', not the very line
- $ sed -n '/Linux/{s/.*//;x;d;};x;p;${x;p;}' file | sed '/^$/d' #Delete the line containing the pattern 'Linux', also the line before the pattern
- $ sed -n '/Linux/{x;d;};1h;1!{x;p;};${x;p;}' file #Delete only the line prior to the line containing the pattern 'Linux', not the very line
- $ sed -n '/Linux/{N;s/.*//;x;d;};x;p;${x;p;}' file | sed '/^$/d' #Delete the line containing the pattern 'Linux', the line before, the line after