SED series: Multi-Command execution

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.