Syntax:
#
sed-e ' command '-e ' command ' filename
Note:-e option is optional-sed with a single command. Sed would execute the each set of command while processing INP UT from the pattern buffer.
Let's create the sample file first
# cat Thegeekstuff.txt
1. Linux-sysadmin, Scripting etc.
2. Databases-oracle, MySQL etc.
3. Hardware
4. Security (Firewall, Network, Online security etc)
5. Storage
6. Cool Gadgets and websites
7. Productivity (Too Many technologies to explore, not much time available)
8. Website Design
9. Software Development
10.windows-sysadmin, reboot etc
.
Example 1: Delete lines 1th and 4th
$sed-E ' 4d '-e ' 2d ' thegeekstuff.txt
1. Linux-sysadmin, Scripting etc.
3. Hardware
5. Storage
6. Cool Gadgets and websites
7. Productivity (Too Many technologies to explore, not much time available)
8. Website Design
9. Software Development
10.windows-sysadmin, reboot etc.
Example 2: Output pattern matching 1 and pattern matching row 2
$sed-N-E '/storage/p '-e/software/p thegeekstuff.txt
5. Storage
9. Software Development
$
Example 3: Delete the first row, the last line, and the empty line
$sed-E ' 1d '-e ' $d '/^$/d ' thegeekstuff.txt
Sed:can ' t read/^$/d:no such file or directory
2. Databases-oracle, MySQL etc.
3. Hardware
4. Security (Firewall, Network, Online security etc)
5. Storage
6. Cool Gadgets and websites
7. Productivity (Too Many technologies to explore, not much time available)
8. Website Design
9. Software Development
$sed '
> 1d
> $d
>/^$/d
> ' Thegeekstuff.txt
2. Databases-oracle, MySQL etc.
3. Hardware
4. Security (Firewall, Network, Online security etc)
5. Storage
6. Cool Gadgets and websites
7. Productivity (Too Many technologies to explore, not much time available)
8. Website Design
9. Software Development
$
SED series: Multi-Command execution