Add a column to a file using a shell script

Source: Internet
Author: User

My college classmates asked me a script question, presumably the need is to see all the ports open, but also to know the application path of each port, and to be flush with the previous data, is to add a column of data. I butt eyes, very easy, but because of the busy, so I said at noon to send him the past, but to his own writing, all kinds of problems ah, the use of awk find and find, have to say awk is very great, the script is as follows:

show_path.sh

#!/bin/bashpid= ' netstat-lntup |awk  '{if (nr>2) {print $7}}' / ' ' {print $} ' `  for inch $pid  Do   pwdx $pid Done

Execute Script all.sh

#!/bin/'{if (nr>2) print}' >>\ t "

The runtime only needs to execute the all.sh script, as follows:

Add a column to a file using a shell script

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.