- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- need awk Help from experts
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2005 08:43 PM
11-30-2005 08:43 PM
need awk Help from experts
i have approx 500 files with .csv extension
and i want to produce a final report from these
csv files.ALL of theses files have such a kind of strings which i have to use on my report;
Computer Name,Fully Qualified DNS Name,,0,Computer Name,
Memory,,Physical Memory,0,Total,
CPU,,CPU Properties,0,CPU Type,
from the original file(csv file);
Computer Name,Fully Qualified DNS Name,,0,Computer Name,MNTRANKTPC00938
CPU,,CPU Properties,0,CPU Type,Unknown; 3000 MHz
Memory,,Physical Memory,0,Total,190 MB
so My report will be like;
computer_name cpu mem
--------------- ---- ------
MNTRANKTPC00938 3000 Mhz 190 Mb
how can i produce such a kind of report via
awk?
!!!Points start with 5!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2005 08:54 PM
11-30-2005 08:54 PM
Re: need awk Help from experts
# awk -F "," 'BEGIN{print "Computer_name cpu memory";}{printf $NF" ";}END{printf "\n";}' test.csv
Computer_name cpu memory
MNTRANKTPC00938 Unknown; 3000 MHz 190 MB
Question:
1) CPU,,CPU Properties,0,CPU Type,Unknown; 3000 MHz -- Is this format correct?
2) Is every file contains only those 3 details?
3) do you want to generate a final report with computer_name ...* and get names from differenct csv files and make combined report?
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2005 09:07 PM
11-30-2005 09:07 PM
Re: need awk Help from experts
I am continuing with available format as,
( echo "computer_name cpu memory";
for file in `find
do
awk -F "," '!/^$/{ if ( $NF ~ "Unknown") { split ($NF,a,"; ");printf a[2]" ";}else {printf $NF" ";}}END{printf "\n"}' $file
done ) > final.report
Change
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2005 09:08 PM
11-30-2005 09:08 PM
Re: need awk Help from experts
1- yes.it is correct.This csv file is being
generated when the computer logon to domain
so normally there are more information in this file hardware-software information.so i
only selected the lines which i want to produce a report
2- No.
3- Each *.csv file named as like the computername.so for example if MNTRANKTPC00938 logon to domain then it generates MNTRANKTPC00938.csv so information
cpu-mem-computer name information included in this file so i have to read all these *.csv files and get these information onto my report.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2005 09:15 PM
11-30-2005 09:15 PM
Re: need awk Help from experts
see the attachment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2005 09:23 PM
11-30-2005 09:23 PM
Re: need awk Help from experts
#!/bin/ksh
#report.ksh
#USER Input - Needed
FINALREPORT_FILE=/tmp/final.report
CSV_DIRECTORY=/tmp/
if [[ ! -f ${FINALREPORT_FILE ]]
then
echo "Computer_Name CPU Memory" >| ${FINALREPORT_FILE}
fi
find ${CSV_DIRECTORY} -type f -name "*.csv" | while read file;
do
awk -F "," '!/^$/{ if ( $NF ~ "Unknown") { split ($NF,a,"; ");printf a[2]" ";}else {printf $NF" ";}}END{printf "\n"}' ${file}
done >> ${FINALREPORT_FILE}
# END
exit 0
################
Change USER Input part with your requirement.
# chmod u+x report.ksh
# ./report.ksh
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2005 09:37 PM
11-30-2005 09:37 PM
Re: need awk Help from experts
Change script as,
#!/bin/ksh
#report.ksh
#USER Input - Needed
FINALREPORT_FILE=/tmp/final.report
CSV_DIRECTORY=/tmp/
if [[ ! -f ${FINALREPORT_FILE ]]
then
echo "Computer_Name CPU Memory" >| ${FINALREPORT_FILE}
fi
find ${CSV_DIRECTORY} -type f -name "*.csv" | while read file;
do
computer=$(grep "Fully Qualified DNS Name" $file | grep -v "Class" | head -1 | awk -F"," '{ print $NF }')
cpu=$(grep "CPU.*Unknown" $file | awk -F"; " '{ print $NF }')
memory=$(grep "Physical Memory.*Total" $file | awk -F"," '{ print $NF }')
echo "${computer} ${cpu} ${memory}
done >> ${FINALREPORT_FILE}
# END
exit 0
Use it and post the result of success / failure.
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2005 10:49 PM
11-30-2005 10:49 PM
Re: need awk Help from experts
report.sh[8]: Syntax error at line 10 : `>' is not expected.
#!/bin/ksh
#report.ksh
#USER Input - Needed
FINALREPORT_FILE=/users/cemt/final.report
CSV_DIRECTORY=/users/cemt
if [[ ! -f ${FINALREPORT_FILE ]]
then
echo "Computer_Name CPU Memory" > ${FINALREPORT_FILE}
fi
find ${CSV_DIRECTORY} -type f -name "*.csv" | while read file;
do
computer=$(grep "Fully Qualified DNS Name" $file | grep -v "Class" | head -1 | awk -F"," '{ print $NF }')
cpu=$(grep "CPU.*Unknown" $file | awk -F"; " '{ print $NF }')
memory=$(grep "Physical Memory.*Total" $file | awk -F"," '{ print $NF }')
echo "${computer} ${cpu} ${memory}
done >> ${FINALREPORT_FILE}
# END
exit 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2005 12:39 AM
12-01-2005 12:39 AM
Re: need awk Help from experts
-denver
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2005 12:59 AM
12-01-2005 12:59 AM
Re: need awk Help from experts
i fixed it up.but nothing changed!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2005 01:03 AM
12-01-2005 01:03 AM
Re: need awk Help from experts
There is a missing curly brace. The code should read:
if [[ ! -f ${FINALREPORT_FILE} ]]
then
echo "Computer_Name CPU Memory" > ${FINALREPORT_FILE}
fi
Note also that there is no pipe. He is saying if the file doesn't exist, then create a new one with a heading line.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2005 01:13 AM
12-01-2005 01:13 AM
Re: need awk Help from experts
You exactly right..
${FINALREPORT_FILE}
also i changed echo "${computer} ${cpu} ${memory}
echo "${computer} ${cpu} ${memory}"
Then script seems working and generated the report!!!!
PS:
Hey Muthukumar,
pls send a reply because 10 is still waiting for you..
Thank's again!!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2005 01:24 AM
12-01-2005 01:24 AM
Re: need awk Help from experts
The key to debugging code is to look *near* the offending line. Generally, you will find that the real cause of the error that doesn't make sense is a few lines ahead.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2005 01:36 AM
12-01-2005 01:36 AM
Re: need awk Help from experts
You (again) right...
i sometimes mixe "seeing" & "looking" but
i know there is a nuance so that's the point..
Greetings,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2005 05:52 PM
12-01-2005 05:52 PM