LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 08-23-2012, 02:39 PM   #1
BobbyinMDC
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Rep: Reputation: Disabled
Need to parse numeric values and file paths from a security scan output.


How can I parse a text output to pull out sections delineated by numeric values along with file paths? Example of input data is below. I attempted using awk and sed commands in a script file, but can't quite figure out how to get the output into sections with the appropriate numerical heading and just the file paths. Any good suggestions?
INPUT DATA...
Plugin Plugin Name Severity
1000365 6.6 Find Unauthorized World-Writable Files "6.6 Find Unauthorized World
-Writable Files " : [FAILED] - error message: The following files are world wri
teable: High

/etc/jlumachine.id owner: root, group: root, permissions: 0666
/opt/Symantec/LiveUpdate/liveupdt.log owner: root, group: root, permissions: 06
66
Plugin Plugin Name Severity
1000366 6.7 Find Unauthorized SUID/SGID System Executables "6.7 Find Unauthoriz
ed SUID/SGID System Executables" : [FAILED] - error message: The following file
s are SUID or SGID :
/bin/su owner: root, group: root, permissions: 4755
/bin/ping owner: root, group: root, permissions: 4755
/bin/eject owner: root, group:audio, permissions: 4755
/bin/mount owner: root, group: root, permissions: 4755

Last edited by BobbyinMDC; 08-23-2012 at 02:41 PM.
 
Old 08-23-2012, 03:00 PM   #2
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
Could you give an example of the desired output?
 
Old 08-23-2012, 03:38 PM   #3
BobbyinMDC
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Here is what I'm looking for:
1000365
/etc/jlumachine.id
/opt/Symantec/LiveUpdate/liveupdt.log
1000366
/bin/su
/bin/ping
/bin/eject
/bin/mount
 
Old 08-23-2012, 06:36 PM   #4
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
This doesn't work with paths that contain spaces, but it appears to work with the example assuming the number is always 7 digits:
Code:
awk '{if( $1 ~ /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/ || $1 ~ /^\/\w+/ ) print $1}'
Do you need it to support spaces?

Last edited by byannoni; 08-23-2012 at 07:09 PM. Reason: Revised script
 
1 members found this post helpful.
Old 08-24-2012, 08:25 AM   #5
BobbyinMDC
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thank you Byannoni, this really helps. I tried various combos if statements, but I couldn't master the syntax of parsing the number field. I should be able to use this with an elif statement to handle the blank lines, (usually one after each section). Thanks again.
 
Old 08-24-2012, 08:59 AM   #6
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
Here's one that puts a newline before the number:
Code:
awk '$1 ~ /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/ {print "\n" $1} $1 ~ /^\/\w+/ {print $1}'
 
Old 08-24-2012, 09:01 AM   #7
BobbyinMDC
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Nice Byannoni. Thanks!
 
Old 08-24-2012, 09:09 AM   #8
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
You're welcome!
 
Old 08-24-2012, 12:36 PM   #9
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,698

Rep: Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988
An alternative to not worry about spaces:
Code:
awk '$1 ~ /^[0-9]{7}$/ {print (x?"\n":"") $1;x=1} $1 ~ /^\/\w+/ && gsub(/ owner:.*/,"")' file
This assumes the string ' owner:' is always the first thing after path
 
Old 08-27-2012, 11:06 AM   #10
BobbyinMDC
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thank you as well, Grail. This is even better.

Bobby
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse a CSV file output to text file beto Linux - Newbie 3 04-25-2012 09:45 AM
bash: how to compare REAL numeric values? muebi Linux - General 3 02-28-2012 09:00 AM
BASH scripting: check for numeric values linuxLuser Programming 11 11-14-2011 11:11 AM
Searching for numeric values in PHP TheBeli Programming 5 04-17-2008 04:55 AM
parse error before numeric constant HELPPP Mistro116@yahoo.com Programming 1 10-04-2005 04:19 AM


All times are GMT -5. The time now is 07:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration