?
Solved

sed - script

Posted on 2013-01-24
6
Medium Priority
?
347 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 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
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 

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 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

765 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