Sed & Awk example 2 per day

Source: Internet
Author: User
Sed & amp; Awk uses the p command to output the current patternspace ). In the 1st line of the file, the output of each line is two times: sed&%39%p&%39%employee.txt 101, JohnDoe, CEO101, JohnDoe, CEO102, JasonSmith, ITManager Sed & Awk.
The p command can be used to output the current pattern space ). 1. Output $ sed 'P' employee.txt 101, John Doe, CEO101, John Doe, CEO102, CEO102, Jason Smith, IT Manager102, Jason Smith, IT Manager103, AJ Reddy, Sysadmin103, AJ Reddy, Sysadmin104, Anand Ram, comment 104, Anand Ram, comment 105, Jane Miller, Sales Manager105, Jane Miller, Sales Manager 2. Each row in the file is output only once, use the-n parameter $ sed-n 'P' employee.txt 101, John Doe, CEO102, Jason Smith, IT Manager103, AJ Reddy, Sysadmin104, Anand Ram, Develop Er105, Jane Miller, Sales Manager 3. only the second row $ sed-n '2 P' employee.txt 102, Jason Smith, IT Manager 4. output 1st to 4th rows $ sed-n '1, 4 P' employee.txt 101, John Doe, CEO102, Jason Smith, IT Manager103, Raj Reddy, Sysadmin104, anand Ram, Developer 5, output 2nd to the last line $ sed-n'2, $ p 'employee.txt 102, Jason Smith, IT Manager103, AJ Reddy, Sysadmin104, Anand Ram, ipv105, jane Miller, Sales Manager 6, and output an odd number of rows $ sed-n' 1 ~ 2 p 'employee.txt 101, John Doe, CEO103, AJ Reddy, Sysadmin105, Jane Miller, Sales Managern ~ M indicates that the execution starts from line n and is performed once per line m, 1 ~ 2 Match 1, 3, 5, 7...; 2 ~ 2 Match 2, 4, 6, 8...; 2 ~ 3 Match 2, 5, 8, 11 .... 7. output the rows matching Jane $ sed-n'/Jane/p' employee.txt 105, Jane Miller, sales Manager 8. output data from the row matching Jason to the $ sed-n '/Jason/, 4 p 'employee.txt 4th, Jason Smith, IT Manager103, Raj Reddy, Sysadmin104, anand Ram, listen 9, output from the first line that matches AJ to the last $ sed-n'/Raj/, $ p 'employee.txt 103, Raj Reddy, Sysadmin104, Anand Ram, choose 105, jane Miller, Sales Manager 10. output the rows from AJ to Jane $ sed-n '/aj/,/Jane/p' employee.txt 103, AJ Reddy, Sysadmin104, Anand Ram, interval 105, Jane Miller, Sales Manager 11. output the row matching Jason and the second row following it $ sed-n'/Jason/, + 2 p 'employee.txt 102, Jason Smith, IT Manager103, Raj Reddy, Sysadmin104, Anand Ram, Developer
Related Article

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.