Better way to do this?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Better way to do this?
# 1  
Old 03-19-2010
Better way to do this?

Hi Experts,

After the great suggestions I received yesterday, i'm back again, asking for more Smilie.
I have close to 8-10 lines of code performing an operation, id like to know, if there is a more compact way to do this.

# Removes the first line which is a message
Code:
awk 'match($0,"The following message") == 0 {print $0}' results_Linux.out > tmp
mv tmp results_Linux.out

# Removes the empty lines in the file
Code:
cat results_Linux.out | awk '$0!~/^$/ {print $0}' > tmp
mv tmp results_Linux.out

# Removes the last part of each line and adds a URL to the end
Code:
sed -e 's|WAITING (Being queued on farm)|http://dte/dte30/faces/monitorPage/jobId=|' results_Linux.out > tmp
mv tmp results_Linux.out

# Adds the first word of each line to the end of the line as well
Code:
awk '{print $0$1}' results_Linux.out > tmp
mv tmp results_Linux.out

# Send a mail to the user
Code:
userID=`whoami`
datetime=`date`
cat results_Linux.out | mail -s "Linux Run Results for - [$userID] executed on - [$datetime]"  $EMAIL

# 2  
Old 03-19-2010
You could drop the multiple mv commands. Do it as

Code:
awk 'match($0,"The following message") == 0 {print $0}' results_Linux.out > tmp

awk '$0!~/^$/ {print $0}' tmp > results_Linux.out

sed -e 's|WAITING (Being queued on farm)|http://dte/dte30/faces/monitorPage/jobId=|' results_Linux.out > tmp

awk '{print $0$1}' tmp > results_Linux.out 

userID=`whoami`
datetime=`date`
cat results_Linux.out | mail -s "Linux Run Results for - [$userID] executed on - [$datetime]"  $EMAIL

I think it may be possible to combine the multiple awk's into a single awk command. Or even perhaps the whole thing can be done in perl.
# 3  
Old 03-19-2010
Try this:
Code:
awk '!/The following message/ && NF {
  sub("WAITING \(Being queued on farm\)","http://dte/dte30/faces/monitorPage/jobId=")
  print $0$1
}' results_Linux.out > tmp
mv tmp results_Linux.out

userID=`whoami`
datetime=`date`
cat results_Linux.out | mail -s "Linux Run Results for - [$userID] executed on - [$datetime]"  $EMAIL

Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question