Created جمعه 17 اوت 2012
Introduction to Sed
-------------------
دستور sed
---------------------
--------------------
kkkkراهنمایی آقاهدایت برای تبدیل حروف کوچک و بزرگ در لینکها
href="[^"]*"
src="[^"]*"
kkkکد زیر باید از غیر مسیر جاری اجرا شود و گرنه خودش را تغییر میدهد به حروف کوچک و کامل اجرا نمیشود
find -iname "*" -exec sed -i '/href="[^"]*"/ y/QWERTYUIOPASDFGHJKLZXCVBNM/qwertyuiopasdfghjklzxcvbnm/' {} \; -exec sed -i '/src="[^"]*"/ y/QWERTYUIOPASDFGHJKLZXCVBNM/qwertyuiopasdfghjklzxcvbnm/' {} \;
------------------------
kkkکار فلاگ /g تبدیل تمام موارد یافته شده در فایل است نه فقط اولی
sed 's/Linux/Linux-Unix/g' thegeekstuff.txt
sed 's/Linux/Linux-Unix/2' thegeekstuff.txt
-----------------
ر این مثال به جای استفاده از «*[A-Za-z]» که لغاتی مانند «won't» را شامل نمی شود از «*[^]» که با هر چیز به غیر از فاصله منطبق می شود استفاده می کنیم. در عین حال این الگو با هر چیزی منطبق می شود ، چرا که * به معنی صفر یا هر تعداد است.
sed 's/[^ ]*/(&)/' <old >new
---------------------------------
This sed example deletes last 3 characters from each line.
$ sed 's/...$//' thegeekstuff.txt
-------------------
In this example, there are two commands seperated by ‘;’
First command replaces the lines starting with the # to the blank lines
Second command deletes the empty lines.
$ sed -e 's/#.*//;/^$/d' thegeekstuff.txt
-----------------
kkkkحدف تگها
sed -e 's/<[^>]*>//g'
sed -n ‘/^$/!{s/]*>//g;p;}’
http://www.unix.com/linux/45584-how-remove-only-html-tags-inside-file.html
-------------------
How would one rearrange the columns output by ls -al?
On AIX, which lacks gnu/Linux’s excellent features, I need ls -al to output …
The filename -rwxrwxrwx 1 root root 12345678 …
… instead of …
-rwxrwxrwx 1 root root 12345678 Jan 01 2009 The filename
Thanks!
Hope this helps,
$ ls -al The\ Geek\ Stuff | sed -e ‘s/\(\([^ ]* \+\)\{8\}\)\(.*\)$/\3 \1/g’
The Geek Stuff -rw-r–r– 1 user group 0 Sep 30 21:50