Solved

sed - script

Posted on 2013-01-24
6
342 Views
Last Modified: 2013-02-11
I am trying to understand these line. Can some one explain as i am new to scripting.


egrep 'PASS|FAIL' $LOGFILE | wc -l | sed 's/^ *//;s/ *$//'

grep PASS $LOGFILE | wc -l | sed 's/^ *//;s/ *$//'

grep FAIL $LOGFILE | wc -l | sed 's/^ *//;s/ *$//'

echo $SCAN_PASS/$SCAN_TOTAL*100 | bc -l | awk -F. '{print $1}'| sed 's/^ *//;s/ *$//'
0
Comment
Question by:ittechlab
  • 3
  • 2
6 Comments
 

Author Comment

by:ittechlab
ID: 38814808
what is this mean?

sed 's/^ *//;s/ *$//'
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38814824
This removes empty lines as well as lines containing only spaces.
0
 
LVL 19

Assisted Solution

by:simon3270
simon3270 earned 420 total points
ID: 38814859
The 's/^ *//' removes all leading spaces.  The 's/ *$//' removds all trailing spaces.  SO, for example, the result of the first egrep line is the number of PASS or FAIL lines in the LOGFILE, with no spaces aound the number.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:ittechlab
ID: 38814917
Thanks


$SCAN_PASS=10
$SCAN_TOTAL=20

can you please advise what is this line does. do we need bc -l?

$SCAN_PASS/$SCAN_TOTAL*100 | bc -l | awk -F. '{print $1}'| sed 's/^ *//;s/ *$//'
0
 

Author Comment

by:ittechlab
ID: 38815561
sorry.

SCAN_PASS=10
SCAN_TOTAL=20

not

$SCAN_PASS=10
$SCAN_TOTAL=20
0
 
LVL 19

Accepted Solution

by:
simon3270 earned 420 total points
ID: 38817765
"bc" is the "Basic Calculator".  What you are doing is feeding the calculation $SCAN_PASS divided by $SCAN_TOTAL multiplied by 100 into bc - this gives the percentage of successful scans out of the total.  (you need an "echo" at the start of the line).

The result of your calculation is 10/20*100 = 50.00000000
The "awk" command then splits input on the decimal point, and prints out the bit before the decimal.  The sed at the end removes the leading and trailing spaces.

One thing I woudl add to this is to put double-quotes round the SCAN_PASS/SCAN_TOTAL*100 bit.

There are other was of doing this - you could get awk to do the calculation, and to print out only the integer part, and remove (actually, not include) the spaces.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question