![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2011
Posts: 2
Rep Power: 0
![]() |
add a additional column in csv file
thanks for allwoing me to discuss in this forum
GIVEN BELOW A simple shell script which will ask for the user to input a PC name and it will produce the output in CSV with the PC name #! /bin/bash read -p "enter the PC name :" pc #checking for netstat report netstat -pant |sed '1,2d' |awk '{$1=$1; print}' OFS=, > "$pc _netstat.csv" #checking for process list ps aux | awk '{$1=$1; print}' OFS=, | cut -d ',' -f1-4,10,11 | awk ' BEGIN{FS=","} {print $2 "," $1 "," $5 "," $6 ", " $3 "," $4} END{}' > "$pc _process.csv" The output is attached along with this thread Now how can i make changes in script so that i should get a additional column in the beginning of csv file with PC name in each field.... suppose if Lenovo_pc is the PC Name which user entered then output should be as follows-- netstat_csv file Lenovo_pc,tcp,0,0,127.0.0.1:3310,0.0.0.0 ,LISTEN,3203/clamdLenovo_pc,tcp,0,0,127.0.0.1:631,0.0.0.0 ,LISTEN,3148/cupsdLenovo_pc,tcp,0,0,192.168.2.101:56014,66.220.153.29:80,TIME_WAIT,- process_csv file Lenovo_pc,1,root,0:01,init,0,0 Lenovo_pc,2,root,0:00,[kthreadd],0,0 Lenovo_pc,3,root,0:00,[migration/0],0,0 Lenovo_pc,4,root,0:00,[ksoftirqd/0],0,0 Lenovo_pc,5,root,0:00,[migration/1],0,0 Lenovo_pc,6,root,0:00,[ksoftirqd/1],0,0 Lenovo_pc,7,root,0:00,[events/0],0,0 any suggestions in this regard is greatly appreciated thanks in advance |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Dec 2006
Posts: 572
Rep Power: 7
![]() |
Re: add a additional column in csv file
Something like perl -pi -e 's/^/Lenovo_pc/'
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Saving File Metadata into CSV | leo2011 | Bash / Shell Scripting | 0 | Mar 9th, 2011 5:57 AM |
| input matches excel file from column 1 and uses column 3 from that row to print info, how? | throstur | Python | 1 | May 6th, 2010 11:05 AM |
| Add a jpg image to a GZ file | RareDevil | PHP | 2 | Jul 10th, 2009 7:05 PM |
| C++ column and inputting file help? | kayliu | C++ | 3 | Apr 26th, 2009 12:27 PM |
| Errors whenever i add a new .cpp file | M.retsam | C++ | 4 | Dec 10th, 2008 8:57 PM |