Extract lines from file using keywords using script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract lines from file using keywords using script
Prev   Next
# 1  
Old 02-14-2013
Extract lines from file using keywords using script

Hi

I need some lines of text from input file using keywords.

Inputfile

Code:
IP IS 10.238.52.65
[local]pun-ras-bng-mhs-01#context  bsnl.in

Card Status :  1:0,  2:1,  3:1,  4:1,  5:0,  6:0,  7:0, 
               8:0,  9:1, 10:0, 11:0, 12:0, 13:0, 14:1, 

Max Circuits:  1:     0,   2: 32768,   3: 32768,   4: 32768,   5:     0,  
               6:     0,   7:     0,   8:     0,   9: 16384,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:  4096,  

Num Circuits (L2TP):
               1:     0,   2:     0,   3:     0,   4:     0,   5:     0,  
               6:     0,   7:     0,   8:     0,   9:     0,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:     0,  

Num Circuits (MIP HA):
               1:     0,   2:     0,   3:     0,   4:     0,   5:     0,  
               6:     0,   7:     0,   8:     0,   9:     0,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:     0,  

Num Circuits (MIP FA):
               1:     0,   2:     0,   3:     0,   4:     0,   5:     0,  
               6:     0,   7:     0,   8:     0,   9:     0,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:     0,  

Num Circuits (OTHER):
               1:     0,   2:     0,   3:     0,   4:     0,   5:     0,  
               6:     0,   7:     0,   8:     0,   9:     0,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:     0,  

Num Circuits (TOTAL):
               1:     4,   2:  8959,   3: 10591,   4:     4,   5:     4,  
               6:     0,   7:     1,   8:     0,   9:    12,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:     1,  

Num Circuits ((null)):
               1:     4,   2:  8959,   3: 10591,   4:     4,   5:     4,  
               6:     0,   7:     1,   8:     0,   9:    12,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:     1,  


IP IS 10.238.56.225
[local]ngp-ras-bng-cto-01#context  bsnl.in


Card Status :  1:1,  2:1,  3:1,  4:1,  5:0,  6:0,  7:0, 
               8:0,  9:1, 10:0, 11:0, 12:0, 13:0, 14:0, 

Max Circuits:  1: 32768,   2: 32768,   3: 32768,   4: 32768,   5:     0,  
               6:     0,   7:     0,   8:     0,   9: 16384,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:     0,  

Num Circuits (L2TP):
               1:     0,   2:     0,   3:     0,   4:     0,   5:     0,  
               6:     0,   7:     0,   8:     0,   9:     0,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:     0,  

Num Circuits (MIP HA):
               1:     0,   2:     0,   3:     0,   4:     0,   5:     0,  
               6:     0,   7:     0,   8:     0,   9:     0,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:     0,  

Num Circuits (MIP FA):
               1:     0,   2:     0,   3:     0,   4:     0,   5:     0,  
               6:     0,   7:     0,   8:     0,   9:     0,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:     0,  

Num Circuits (OTHER):
               1:     0,   2:     0,   3:     0,   4:     0,   5:     0,  
               6:     0,   7:     0,   8:     0,   9:     0,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:     0,  

Num Circuits (TOTAL):
               1:  4916,   2: 10976,   3:  9385,   4:     7,   5:     0,  
               6:     0,   7:     1,   8:     0,   9:    14,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:     0,  

Num Circuits ((null)):
               1:  4916,   2: 10976,   3:  9385,   4:     7,   5:     0,  
               6:     0,   7:     1,   8:     0,   9:    14,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:     0,

Required output will be like below

Code:
10.238.52.65

pun-ras-bng-mhs-01

Card Status :  1:0,  2:1,  3:1,  4:1,  5:0,  6:0,  7:0, 
               8:0,  9:1, 10:0, 11:0, 12:0, 13:0, 14:1, 

Max Circuits:  1:     0,   2: 32768,   3: 32768,   4: 32768,   5:     0,  
               6:     0,   7:     0,   8:     0,   9: 16384,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:  4096,  

Num Circuits (TOTAL):
               1:     4,   2:  8959,   3: 10591,   4:     4,   5:     4,  
               6:     0,   7:     1,   8:     0,   9:    12,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:     1,  


10.238.56.225

pun-ras-bng-mhs-01

Card Status :  1:1,  2:1,  3:1,  4:1,  5:0,  6:0,  7:0, 
               8:0,  9:1, 10:0, 11:0, 12:0, 13:0, 14:0, 

Max Circuits:  1: 32768,   2: 32768,   3: 32768,   4: 32768,   5:     0,  
               6:     0,   7:     0,   8:     0,   9: 16384,  10:     0,  



Num Circuits (TOTAL):
               1:  4916,   2: 10976,   3:  9385,   4:     7,   5:     0,  
               6:     0,   7:     1,   8:     0,   9:    14,  10:     0,  
              11:     0,  12:     0,  13:     0,  14:     0,  
              11:     0,  12:     0,  13:     0,  14:     0,

keywords are IP IS,cont , Card Status (two lines with this key word).
Max Circuits(two lines with this key word).
TOTAL(two lines with this key word).

can anybody help to get output

Last edited by vbe; 02-14-2013 at 09:37 AM.. Reason: code tags please not HTML...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Copy Lines between Keywords & paste them to another file

hi, I have Multiple files with the following data : File1 100414 DR1 END XXXXX Test1 Test2 Test3 Test4 Test5 Test6 END 100514 DR2 END XXXXX Test7 Test8 Test9 Test10 Test11 Test12 END 100614 DR3 (5 Replies)
Discussion started by: newageBATMAN
5 Replies

2. Shell Programming and Scripting

Display lines between keywords inclusive

Hi, I have a file that contains a lot of lines that are repetitive. I am interested in grepping the following section which is repetitive. ::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::: <Address> <Street>xxxy</Street> ... (3 Replies)
Discussion started by: jakSun8
3 Replies

3. Shell Programming and Scripting

Extract word between two KEYWORDS

Hi I want to extract all the words between two keywords HELLO & BYE. eg: Input 1_HELLO_HOW_ARE_YOU_BYE_TEST 1_HELLO_WHERE_ARE_BYE_TEST 1_HELLO_HOW_BYE_TEST Output Required: HOW_ARE_YOU WHERE_ARE HOW (7 Replies)
Discussion started by: dashing201
7 Replies

4. Shell Programming and Scripting

Script needed to extract few lines from file

Hello, I need a utility script or command that will extract the following lines from a file based on a 'word' contain in a line. For example my file contains lot of lines. So if i pass 1800182 to the script/command it should return everything between 1st RequestNetRates tag before it and 1st... (4 Replies)
Discussion started by: jakSun8
4 Replies

5. Shell Programming and Scripting

HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching

I have a LOG file which looks like this Import started at: Mon Jul 23 02:13:01 EDT 2012 Initialization completed in 2.146 seconds. -------------------------------------------------------------------------------- -- Import summary for Import item: PolicyInformation... (8 Replies)
Discussion started by: biztank
8 Replies

6. UNIX for Dummies Questions & Answers

Reading specific lines from a file using index or keywords

Hello I want to read from a file which contains email addresses. The file format is like this. from@mail.com to1@mail.com to2@mail.com cc@mail.com bcc@mail.com I'll have to read from such file and assign the email addresses to respective variables. frommail =... (11 Replies)
Discussion started by: Kyaw Lwin Phyo
11 Replies

7. Shell Programming and Scripting

copy range of lines in a file based on keywords from another file

Hi Guys, I have the following problem. I have original file (org.txt) that looks like this module v_1(.....) //arbitrary number of text lines endmodule module v_2(....) //arbitrary number of text lines endmodule module v_3(...) //arbitrary number of text lines endmodule module... (6 Replies)
Discussion started by: kaaliakahn
6 Replies

8. Shell Programming and Scripting

Sorting lines based on keywords for MySQL script

the thing which i require is very very complex.. i tried hard to find the solution but couldnt.. the thing i need to achieve is say i have a file cat delta.sql CREATE VIEW Austin Etc etc . . . CREATE VIEW Barabara AS SELECT blah blah blah FROM Austin z, Cluster s, Instance i WHERE... (4 Replies)
Discussion started by: vivek d r
4 Replies

9. Shell Programming and Scripting

Script that extract some lines from a file lookin into another

I want a ksh script that parse two files (text files, actually my original files are .xls) - input data: - one file file1 containig lines separated by spaces (or other delimiter) - 2nd one file2 contain only one numerical value in a line (for simplicity but it might of the same form as the 1st)... (7 Replies)
Discussion started by: heartwork
7 Replies

10. Shell Programming and Scripting

Capture lines based on keywords

Hello everyone, I am trying to write a script that will capture few lines from a text file based on 2 keywords in the first line and 1 keyword in the last one. It could also be based on the first line only + the folllowing 3 lines. Could some one help or give directions. Thanks. (4 Replies)
Discussion started by: nimo
4 Replies
Login or Register to Ask a Question