Solved

sed - script

Posted on 2013-01-24
6
340 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VMWare 6 crashing 14 54
Linux "time" command output redirection 16 74
Oracle 12c patching 1 32
Linux Scripting 3 49
I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
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…
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now