Searching and extracting text from output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching and extracting text from output
# 1  
Old 12-06-2007
Searching and extracting text from output

I have the following output which I need to obtain the values for "Next Seq is xxx" and "Last Seq is xxx" and "Pending count is xxx". You will notice that the number of words prior to that value can be variable hence the reason for asking this question.

LINECMD> Line /xxx///ABC9_SND is UP. Snd-Enabled. Tracing enabled. Line information: "STARTNG-Up Cmd" Next seq is 1 Last seq is 0 Processed count is 0 Pending count is 4 Line /xxx///ABC9_SND is connected to: /xxx///ABC9_OUTQ
LINECMD> Line /xxx///abc0_SND is UP. Snd-Enabled. Tracing enabled. Line information: "STARTNG-Up Cmd" Next seq is 1 Last seq is 0 Processed count is 0 Pending count is 4 Line /xxx///RGW0_SND is connected to: /xxx///XYW0_OUTQ
LINECMD> Line /xxx///BCDPRT is UP. Line information: "209134" Next seq is 8 Last seq is 7 Processed count is 7 Pending count is 0 ACK'ing is not enabled Line /xxx///BCDPPRT is connected to: /xxx///EXCPPRTQ /xxx/MTRANS//EXCPPRTQ
LINECMD> Line /xxx///XYW_POST_01 is UP. Line information: "UP POSTING LOGGED IN" Next seq is 10 Last seq is 9 Processed count is 9 Pending count is 0 Line /xxx///XYW_POST_01 is connected to: /xxx///XYW_AUTQ

I have looked at using awk for it but I am unable to get it to work with the variable position. Any assitance in getting this resolved would be appreicated.
# 2  
Old 12-06-2007
to start with

Code:
sed 's/.*\(Next seq is \)\([0-9]*\).*/\1\2/' a

# 3  
Old 12-06-2007
my current code

That didn't give me the results I was after. Heres a copy of something that appears to work but I am sure it could be done better

echo 'LINECMD> Line ////AT_VLD is UP. Line information: "CONNECTED: 1, 2, 3" Next seq is 8880 Last seq is 0 Processed count is 0 Pending count is 0'|awk 'match($0,"Next seq is [0-9]*") {print substr($0,RSTART, RLENGTH)}'|awk '{ print $4} '


result = 8880 # What I want to see

Now that I have obtained that how can I obtain the information for the line information i.e. "CONNECTED: 1, 2, 3" or "UP"(depending on what is returned)
# 4  
Old 12-07-2007
My final solution

Just in case anyone is interested here is my final code that worked as I was expecting it

LINE_INFO=`echo $STATUS|awk 'match($0,"Line information: \".\*\" ") {print substr($0,RSTART, RLENGTH)}'|awk '{ print $3,$4,$5,$6,$7} '`
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help searching through a text file.

I'm trying to get one specific number out of a text file, in order to use as part of an algorithm in a shell script. It will always come after a specific string and that string won't appear anywhere else in the file. So I'm trying to search through the file for that one string, then grab the... (2 Replies)
Discussion started by: mikedigornio
2 Replies

2. Shell Programming and Scripting

Searching for a pattern and extracting records related to that pattern

Hi there, Looking forward to your advice for the below: I have a file which contains 2 paragraphs related to a particular pattern. I have to search for those paragraphs from a log file and then print a particular line from those paragraphs. Sample: I have one file with the fixed... (3 Replies)
Discussion started by: danish0909
3 Replies

3. Shell Programming and Scripting

Extracting text from within a section of text using AWK

I have a command which returns the below output. How can I write a script to extract mainhost and secondhost from this output and put it into an array? I may sometimes have more hosts like thirdhost. I am redirecting this output to a variable. So I guess there should be a awk or sed command to... (7 Replies)
Discussion started by: heykiran
7 Replies

4. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

5. UNIX for Advanced & Expert Users

Searching and extracting records

Hello, I have a file with DNA sequences and I want to extract some records by searching them with a word in it and then write the whole record into another file. I am new to perl and having trouble to extract the whole record. Instead I am only able to write the line that contains the word. Can... (2 Replies)
Discussion started by: bjorngill
2 Replies

6. Shell Programming and Scripting

String searching and output to a file in a formatted text

Hi, I'm very new to UNIX scripting and find quite difficult to understand simple UNIX syntax. Really appreciat if somebody could help me to give simple codes for my below problems:- 1) I need to search for a string "TTOH 8031950001" in a files which filename will be "*host*'. For example, the... (3 Replies)
Discussion started by: cuji
3 Replies

7. UNIX for Dummies Questions & Answers

extracting text and reusing the text to rename file

Hi, I have some ps files where I want to ectract/copy a certain number from and use that number to rename the ps file. eg: 'file.ps' contains following text: 14 (09 01 932688 0)t the text can be variable, the only fixed element is the '14 ('. The problem is that the fixed element can appear... (7 Replies)
Discussion started by: JohnDS
7 Replies

8. Shell Programming and Scripting

Extracting a string from one file and searching the same string in other files

Hi, Need to extract a string from one file and search the same in other files. Ex: I have file1 of hundred lines with no delimiters not even space. I have 3 more files. I should get 1 to 10 characters say substring from each line of file1 and search that string in rest of the files and get... (1 Reply)
Discussion started by: mohancrr
1 Replies

9. Linux

Searching for text in files

Is there anyway that I can run a search of all files for matching strings(or even just a subset of all files) from the command line on Linux system? e.g check all files in the current directory that have 'cisco' in them........ find doesnt seem to be right as it only(well it appears to me... (2 Replies)
Discussion started by: GandalfWhite
2 Replies

10. Shell Programming and Scripting

Help with searching a text file

Hello all! I've been working for days on this and it is really bugging me!! Here's my dilemma: Say I have a very large text file which contains fields delimited my a ':' which logs various records. Each record is separated by a newline character, therefore I can search for lines with... (6 Replies)
Discussion started by: thekid2
6 Replies
Login or Register to Ask a Question