Extremely rusty on my scripting and need help!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extremely rusty on my scripting and need help!
# 1  
Old 01-05-2010
Extremely rusty on my scripting and need help!

Hello everyone, hope that your holiday's were good. I am getting back into some System Admin work after taking last year off and feeling a little rust.

I am doing some reporting and I have a log file that I need to pull some information from. And here is what the extract is from the log file. It has a bunch of data that I don't need but does contain the stuff I need.

*--*--*--*--*--*--*--*--*
( interface data )
*--*--*--*--*--*--*--*--*

interface speed pkts pkts pkts pkts bits bits errors trunk
Mb/s in out drop coll in out
admn DN 100 FD 0 1 0 0 0 560 0
I.1 UP 1000 FD 3.578G 4.068G 88917 0 9.919T 21.37T 0
I.2 UP 1000 FD 4.620G 4.063G 88506 0 21.91T 10.30T 0

I need to pull the lines (roughly 10) that are following from the interface data line. I am having a problem doing that and was seeing if you guys had something quick and easy.

Thanks in Advance.
# 2  
Old 01-05-2010

Use sed or awk to extract the line you want.

If you want more detail, you'll have to be more specific.

What do you need?
What don't you need?
# 3  
Old 01-05-2010
Sorry I had a lot of detail in the first post that got wiped somehow. I am in need of the line entries from the log file that follow the Interface Data Line so that i could report on dropped packets. So I need the complete lines for the interfaces so that I can review and see if there is any dropped packets. I ended up finding some old sed commands from some of my older scripts and it will work for the extraction but see if there is something cleaner to keep for the formating of the lines from the orginal data file into the new file. Cause it currently pulls it but outputs it into a single string.

Here is what I have found and am trying to use.

DRPPKT=`sed -n '/( interface data )/,/( interface trunks )/p' filename`
echo ${DRPPKT}
# 4  
Old 01-05-2010
An example how to print the line with the pattern and 3 lines after the pattern:

Code:
awk '/pattern/{p=1}p && c++<=3' file

# 5  
Old 01-05-2010
Thx Guys I got it. I used a combination of awk and sed in my report generator that worked for me. I hate being rusty and not using a skill for a long time and then relearning it again. Thx for your guys' help!
# 6  
Old 01-05-2010
Glad you got it working. Another method would be:

Code:
grep -A 10 "interface data" your_log

This assumes the proper version of grep though.
# 7  
Old 01-06-2010
Yeah this is on Solaris 10 box and the orginal grep doesn't support the -A function as that was my first solution. Then I went to sunfreeware to grab their version hoping it supported it but no avail. In the past I have pulled the file from a linux box but I didn't have one available. LOL

But thanks for the support.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extremely New to Shell Scripts

I am sorry if this qeustion is silly. (Please see Title of this thread.) Is it possible to build a shell script that 1) runs a nawk command that I know works, to analyze a column of data and 2) after that column is analyzed, if the result is over a certain level, send an email with the... (2 Replies)
Discussion started by: he204035
2 Replies

2. Programming

Working with extremely large numbers in C

Hi All, I am just curious, not programming anything of my own. I know there are libraries like gmp which does all such things. But I really need to know HOW they do all such things i.e. working with extremely large unimaginable numbers which are beyond the integer limit. They can do add,... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

3. UNIX for Dummies Questions & Answers

rusty with cp command -- how to cp all .doc files with .txt extension

I'm rusty with cp, so I was wondering: is it possible to cp all the .doc files in a folder and make them .txt files? Can you use cp to do that? (3 Replies)
Discussion started by: Straitsfan
3 Replies

4. Solaris

Re-sync Taking Extremely Long.

It's almost 3 days now and my resync/re-attach is only at 80%. Is there something I can check in Solaris 10 that would be causing the degradation. It's only a standby machine. My live system completed in 6hrs. (9 Replies)
Discussion started by: ravzter
9 Replies

5. UNIX for Dummies Questions & Answers

help with extremely basic problem

Alright i'm having problems with this loop. Basically once the script is ran a parameter is required. Once entering the parameter it displays that in LIMIT. Alright so now the problem, I need my loop to ask my user for a number, and if that number is less than the limit then sum the input values... (4 Replies)
Discussion started by: tragic54
4 Replies

6. UNIX for Dummies Questions & Answers

Extremely New

I just loaded Cygwin on my XP deskop. I am TRYING to install a program that said it needs this program to run. How do I install or run a program? Keep in mind I just started with Unix yesterday:) (1 Reply)
Discussion started by: gss
1 Replies

7. UNIX for Dummies Questions & Answers

extremely new to unix, need help

Hi, I'm really new and I need help with UNIX. I'm not sure how to use FILE * fp properly, I don't know how to use loops, I don't know how to using i++ or ++i to do things like count the number of scans and print it out, and I don't know how to call functions and use them. I really only know how to... (1 Reply)
Discussion started by: s2pids2pid
1 Replies

8. UNIX for Dummies Questions & Answers

Extremely Interested

As i was reading an article on being a "HACKERS" which was 30 minutes ago thinking that HACKING was the same as CRACKING, after the reading i discovered their difference, a hacker builds the internet while crackers just cracks and annoy like phreaking and breaking into people's computer. That... (5 Replies)
Discussion started by: Punk18
5 Replies

9. UNIX for Dummies Questions & Answers

extremely headache

I need to execute command at remote host from my program. there is rs6000/aix standard command called rexec. unfortunately rexec ask username and password which must supplied interactively, of course it is impossible runned by program. So I have to change rexec command format to make user-name... (5 Replies)
Discussion started by: yatno
5 Replies
Login or Register to Ask a Question