Solved

sed - script

Posted on 2013-01-24
6
344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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