Sed (Stream Editor) is probably the most popular programming utility that handles the text stream under Linux. It’s very powerful and can be used to very complex daily jobs. However, its syntax is not human-readable. Here, some quick usages of the SED are presented.
1. To emulate ‘head’, which prints the first few lines of a file.
ls -l | sed "3q" # the same as ls -l | head -3
2. To replace string A to B, (ignore case)
echo "abcdef" | sed "s/a/b/gi"
3. To replace string A to B,
echo "abcdef" | sed "s/a/b/g"
4. To delete the lines from 5 to 8
ls -l | sed "5,8d"
5. To delete everything.
ls -l | sed "d"
6. To replace string A to B only on lines contain C
ls -l | sed "/C/s/A/B/gi"
7. To delete the lines that contain C
ls -l | sed "/C/d"
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading...
255 wordsloading...
Last Post: Tools on Linux WINE
Next Post: Avoid Javascript whenever possible