?
Solved

sed - script

Posted on 2013-01-24
6
Medium Priority
?
353 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 20

Assisted Solution

by:simon3270
simon3270 earned 1260 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 20

Accepted Solution

by:
simon3270 earned 1260 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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.:
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

864 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