Results 1 to 1 of 1
Hello all...Im just self learning shell scripting and have tried to come up with best way to do this but gave up (really new). So I ask for a little ...
- 01-12-2010 #1Just Joined!
- Join Date
- Nov 2006
- Posts
- 3
Searching for grouping of text and extracting data
Hello all...Im just self learning shell scripting and have tried to come up with best way to do this but gave up (really new). So I ask for a little advise since this is a real world/work request and I need to have solution by tomorrow
I have a huge txt file of raw email headers that in simple terms looks like this: (where "X-header1" is start and "Content" is end. Blank lines are shown for post readability only)
X-header1:blahblah
HeaderIP: 1.2.3.4
Header3:blahblah
To:blahblah
From:blahblah
Subject:blahblah
Content:blahblah
X-header1:foofoo
HeaderIP: 4.3.2.1
Header3:foofoo
To:foofoo
From:foofoo
Subject:foofoo
Content:foofoo
X-header1:barbar
HeaderIP: 6.7.8.9
Header3:barbar
To:barbar
From:barbar
Subject:barbar
Content:barbar
What I need from the pros is the proper code to take each block (from X-header1 to content) and:
1) run this exact command on IP address (results in a pipe delimited output):
Code:2) Output result of of that command to file PLUS each field in the block as pipe delimitedCode:whois -h whois.cymru.com " -v x.x.x.x"
RESULTS:
TO|FROM|SUBJECT|HEADERIP|whois command results
This is a simplified version, once I see the basics Ill modify as needed. I have tried a few things and I get it to work a little but not really! I have tried SED, AWK and GREP but nothing working like I need it to. I again ask only because if time constraints and I would love to see what I am doing wrong.
I completely get the concept in my head/in theory but making it happen seems a little elusive! I know I need to process each block, assign the text to variables, get the IP and run command sending that result to a variable and echo/append all the variables to a file. Rinse, lather and repeat!
Anyway I look forward to response and to see where I went wrong.
My twisted new years resolution is to be command line master by December 2010!! Wish me luck


Reply With Quote