LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-28-2014, 07:25 PM   #16
master-of-puppets
Member
 
Registered: Jun 2011
Posts: 49

Original Poster
Rep: Reputation: Disabled

Quote:
Originally Posted by pan64 View Post
So this file is generated with a perl script. I would suggest you to sum up those things in that perl script. In perl you can print the required result easily there is a built-in sort function. (so print what you want means reverse sort list and print the ordered result)
Hi Daniel,

I removed the sed statement out of the script that removed the string from the output but I still got the same results. Looking at jm_out does it still not have tabs? I also attached the resultant file jm_temp. Thanks for all your help.

Brian
Attached Files
File Type: txt jm_out.txt (38.6 KB, 5 views)
File Type: txt jm_temp.txt (53 Bytes, 9 views)

Last edited by master-of-puppets; 09-28-2014 at 07:27 PM.
 
Old 09-28-2014, 07:58 PM   #17
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
For the InFile which lacks tab characters, try this code ...
Code:
awk -F "" '{if ($1!=" ") {server=$0; next}
            if ($NF==":") {workspace=$0; next}
      print server,workspace,$0}' $InFile5 >$OutFile
Daniel B. Martin

Last edited by danielbmartin; 09-28-2014 at 08:04 PM. Reason: Tighten the code, slightly
 
Old 09-28-2014, 10:40 PM   #18
master-of-puppets
Member
 
Registered: Jun 2011
Posts: 49

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by danielbmartin View Post
For the InFile which lacks tab characters, try this code ...
Code:
awk -F "" '{if ($1!=" ") {server=$0; next}
            if ($NF==":") {workspace=$0; next}
      print server,workspace,$0}' $InFile5 >$OutFile
Daniel B. Martin
Sadly it hangs and doesn't write anything to jm_temp. But hey thank you so much for your time. I think I'll just write a script that does everything including what the Perl script is now doing so I don't have to deal with this crazy output file. Thanks Daniel.

Last edited by master-of-puppets; 09-28-2014 at 10:49 PM.
 
Old 09-29-2014, 07:09 AM   #19
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by master-of-puppets View Post
Sadly it hangs and doesn't write anything to jm_temp.
This is puzzling because I tested with the large real-world InFile which you provided. Ran fine, with subsecond elapsed time, wrote 940 lines to the OutFile.

"Hangs and doesn't write anything" could be the program saying "Okay, I'm running, and waiting for input." Suggestion: check the way you specified the InFile. Keying error?

Daniel B. Martin
 
Old 09-29-2014, 09:08 AM   #20
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
As a side not on possible keying errors, please note the space between -F and the quote "" as if it is not there you will get the issue you have mentioned.
 
1 members found this post helpful.
Old 09-30-2014, 01:06 AM   #21
master-of-puppets
Member
 
Registered: Jun 2011
Posts: 49

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by danielbmartin View Post
This is puzzling because I tested with the large real-world InFile which you provided. Ran fine, with subsecond elapsed time, wrote 940 lines to the OutFile.

"Hangs and doesn't write anything" could be the program saying "Okay, I'm running, and waiting for input." Suggestion: check the way you specified the InFile. Keying error?

Daniel B. Martin
Hi Daniel,

The input file that we were working from was from this person who no longer works for the company and I didn't like the format of his output. It wasn't very useful. I created a new script that runs on each of the four build servers. It looks in local files only so as not to create any unnecessary network traffic. When each of the four servers finish generating their reports the files are then concatenated together and added to a weekly report along with some other data that was generated by my other script. The report is a csv file so that our admin can take it and generate pivot tables and graphs out of it.

Here's the new script that I came up with:

Code:
#!/bin/bash
OUTPUT_DIR=/share/es-ops/Build_Farm_Reports/WorkSpace_Reports
BASE=/export/ws
TODAY=`date +"%m-%d-%y"`
HOSTNAME=`hostname`
case "$HOSTNAME" in
        sideshow) WORKSPACES=(bob mel sideshow-ws2) ;;
        simpsons) WORKSPACES=(bart homer lisa marge releases rt-private simpsons-ws0 simpsons-ws1 simpsons-ws2 vsimpsons-ws) ;;
        moes)     WORKSPACES=(barney carl lenny moes-ws2) ;;
        flanders) WORKSPACES=(flanders-ws0 flanders-ws1 flanders-ws2 maude ned rod todd to-delete) ;;
esac
if ! [ -f $OUTPUT_DIR/$HOSTNAME_top_5_workspace.csv ]; then
echo "Top 5 consumers of space per workspace on server `hostname` $TODAY" > $OUTPUT_DIR/"$HOSTNAME"_top_5_per_workspace.csv
echo ",,," >> $OUTPUT_DIR/"$HOSTNAME"_top_5_per_workspace.csv
echo ",,," >> $OUTPUT_DIR/"$HOSTNAME"_top_5_per_workspace.csv
for v in "${WORKSPACES[@]}"
do
echo "Top 5 consumers on workspace $v" >> $OUTPUT_DIR/"$HOSTNAME"_top_5_per_workspace.csv
echo ",,," >> $OUTPUT_DIR/"$HOSTNAME"_top_5_per_workspace.csv
find $BASE/$v -printf "%u  %s\n" | awk '{user[$1]+=$2}; END{ for( i in user) print i " " user[i]}' | sed -e '/^[0-9]/d' | sed -e 's/root//g' | sed -e '/^ [0-9]/d' | awk '{print $1, $2/1024/1024/1024, "GB"}' | sort -n -r -k2 | head -5 >> $OUTPUT_DIR/"$HOSTNAME"_top_5_per_workspace.csv
echo ",,," >> $OUTPUT_DIR/"$HOSTNAME"_top_5_per_workspace.csv
done
fi
Sample output from host sideshow:
Code:
Top 5 consumers of space per workspace on server sideshow 09-29-14
,,,
,,,
Top 5 consumers on workspace bob
,,,
radickj 97.0708 GB
nichols2 90.4442 GB
sherryr 75.3845 GB
rabii 67.4304 GB
lefevre 39.0694 GB
,,,
Top 5 consumers on workspace mel
,,,
akrishna 125.225 GB
somyalip 124.585 GB
mvijayas 105.741 GB
release 102.279 GB
vuhang 83.4457 GB
,,,
Top 5 consumers on workspace sideshow-ws2
,,,
marlette 124.913 GB
iyershan 35.785 GB
starkd 19.3732 GB
jcook 3.8147e-06 GB
baylisn 3.8147e-06 GB
,,,
I want to thank you Daniel and everyone here. On a rivaling site they banned me for no good reason. They tried to contend that I was trying to trick the people on there into writing my scripts for me. None of the people on here have ever been condescending or judgmental like on that site. Thanks again.

Brian

Last edited by master-of-puppets; 09-30-2014 at 01:08 AM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sum up values from each columns (awk) lcvs Linux - Newbie 10 06-20-2012 04:16 AM
Help needed for using awk to parse a file to make array for bash script tallmtt Programming 12 04-14-2012 01:16 PM
awk's sum not working? grob115 Linux - Newbie 4 04-29-2010 12:44 PM
bash: use file as input into array, parse out other variables from array using awk beeblequix Linux - General 2 11-20-2009 10:07 AM
ssimple shell script to parse a file ~sed or awk stevie_velvet Programming 7 07-14-2006 03:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration