Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 1st, 2011, 4:08 AM   #1
progteam
Newbie
 
Join Date: May 2011
Posts: 2
Rep Power: 0 progteam is on a distinguished road
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/clamd
Lenovo_pc,tcp,0,0,127.0.0.1:631,0.0.0.0,LISTEN,3148/cupsd
Lenovo_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
Attached Files
File Type: zip output.zip (1.7 KB, 0 views)
progteam is offline   Reply With Quote
Old Jun 1st, 2011, 6:16 AM   #2
Rashakil
Expert Programmer
 
Join Date: Dec 2006
Posts: 572
Rep Power: 8 Rashakil will become famous soon enough
Re: add a additional column in csv file

Something like perl -pi -e 's/^/Lenovo_pc/'
Rashakil is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:22 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC