search & select text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search & select text
# 8  
Old 12-21-2010
Code:
awk ' $2 ~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ {print "\n" $2 }  NF == 3 && $1 ~ /^.*=.*$/ {print $0 }' file

This User Gave Thanks to fpmurphy For This Post:
# 9  
Old 12-21-2010
Quote:
Originally Posted by vgersh99
this doesn't produce the desired output:
Code:
SectorPort=3 switchport 20
SectorPort=1 switchport 10
SectorPort=2 switchport 0
192.168.2.1
192.168.3.1
192.168.4.1

@vgersh99
As far as i've tested, for me it worked :

Code:
# egrep -e "Port|RbsL" tst | sed 's/^.* \([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\) .*$/\1/'
192.168.1.1
SectorPort=3 switchport 20
SectorPort=1 switchport 10
SectorPort=2 switchport 0
192.168.2.1
RbsLocalCell=S2C1 featureState 20
RbsLocalCell=S4C1 featureState 40
RbsLocalCell=S1C1 featureState 30
RbsLocalCell=S3C1 featureState 90
192.168.3.1
192.168.4.1
RbsLocalCell=S3C1 maxNumUsers 16
RbsLocalCell=S4C1 maxNumUsers 16

# 10  
Old 12-21-2010
Another approach:
Code:
awk 'NF==4{print s $2;s=RS} /^Obj/{f=1;getline;next} /^=/{f=0}f' file

# 11  
Old 12-22-2010
Quote:
Originally Posted by panyam
something like this:

Code:
 
awk '/^1012/ {print "\n"$2;next } /^Obj/ { s=2;next } /^===============/ {s=s-1;next } s { print }' input_file

panyam;
this solution worked well. thanks for your assist Smilie

---------- Post updated at 10:01 ---------- Previous update was at 09:58 ----------

Quote:
Originally Posted by ctsgnb
Code:
egrep -ve "^Obj|^====|^Tot" input | sed 's/^.* \([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\) .*$/\1/' >output

hi ctsgnb;
this has given some extra lines below&under of my desired lines Smilie

---------- Post updated at 10:03 ---------- Previous update was at 10:01 ----------

Quote:
Originally Posted by vgersh99
A bit verbose, but...
Code:
nawk '/^[0-9][0-9]*-/ {print $2;next}/^Object Att/{p=1;next} p && p--{next} /^Total/{print "";p=-1} !p && !/^==/' myFile

hi vgersh99
thanks but your solution has given completely different lines Smilie

---------- Post updated at 10:05 ---------- Previous update was at 10:03 ----------

Quote:
Originally Posted by fpmurphy
Code:
awk ' $2 ~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ {print "\n" $2 }  NF == 3 && $1 ~ /^.*=.*$/ {print $0 }' file

hi fpmurphy;

this has given the right lines but some of the lines are missing Smilie

---------- Post updated at 10:07 ---------- Previous update was at 10:05 ----------

Quote:
Originally Posted by Franklin52
Another approach:
Code:
awk 'NF==4{print s $2;s=RS} /^Obj/{f=1;getline;next} /^=/{f=0}f' file

hi Franklin52;

your solution has unfortunately given wrong lines. Smilie
thanks

---------- Post updated at 10:11 ---------- Previous update was at 10:07 ----------

Quote:
Originally Posted by ctsgnb
...

Code:
egrep -e "Port|RbsL" input | sed 's/^.* \([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\) .*$/\1/' >output

... just choose the right pattern you need to grep
thanks ctsgnb;
this gave me the result Smilie
# 12  
Old 12-22-2010
Quote:
Originally Posted by gc_sw
hi Franklin52;

your solution has unfortunately given wrong lines. Smilie
This is what I get with the given file:
Code:
$ cat file
101221-18:45:17 192.168.1.1 1.0 PortNodeModel
=========================================================
Object Attribute Value
=========================================================
SectorPort=3 switchport 20
SectorPort=1 switchport 10
SectorPort=2 switchport 0
=========================================================
Total: 3 results
...
...
...
101221-18:45:17 192.168.2.1 1.0 PortNodeModel
=========================================================
Object Attribute Value
=========================================================
RbsLocalCell=S2C1 featureState 20
RbsLocalCell=S4C1 featureState 40
RbsLocalCell=S1C1 featureState 30
RbsLocalCell=S3C1 featureState 90
=========================================================
Total: 4 results
...
...
...
101221-18:45:17 192.168.3.1 1.0 PortNodeModel
=========================================================
Object Attribute Value
=========================================================
=========================================================
Total: 0 results
...
...
...
101221-18:45:17 192.168.4.1 1.0 PortNodeModel
=========================================================
Object Attribute Value
=========================================================
RbsLocalCell=S3C1 maxNumUsers 16
RbsLocalCell=S4C1 maxNumUsers 16
=========================================================
Total: 2 results
$
$
$ awk 'NF==4{print s $2;s=RS} /^Obj/{f=1;getline;next} /^=/{f=0}f' file
192.168.1.1
SectorPort=3 switchport 20
SectorPort=1 switchport 10
SectorPort=2 switchport 0

192.168.2.1
RbsLocalCell=S2C1 featureState 20
RbsLocalCell=S4C1 featureState 40
RbsLocalCell=S1C1 featureState 30
RbsLocalCell=S3C1 featureState 90

192.168.3.1

192.168.4.1
RbsLocalCell=S3C1 maxNumUsers 16
RbsLocalCell=S4C1 maxNumUsers 16

Am I missing something?
This User Gave Thanks to Franklin52 For This Post:
# 13  
Old 12-22-2010
ok Franklin; it is ok now. i'm sorry i have missed your syntax Smilie thanks..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

2. Shell Programming and Scripting

How to select the shortest path in grep search?

Hi, How can I display only one shortest path (A/B/configure)? $ grep configure file.txt A/B/configure A/B/C/configure A/B/C/D/configure Thank you. (9 Replies)
Discussion started by: hce
9 Replies

3. Shell Programming and Scripting

awk + gsub to search multiple input values & replace with located string + extra text

Hi all. I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value. cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies

4. Shell Programming and Scripting

Search & Replacing text within a file

Hi all! I'm a newbie and I'm writing a script which will ask a user for data to search. I will then search for this data using grep and displaying this data back to the screen for the user to see. The user will then enter new data to replace the data searched. Now how do I replace this data... (4 Replies)
Discussion started by: macastor
4 Replies

5. UNIX for Dummies Questions & Answers

select nth file & range of files

Two related questions; 1. how do i select the nth file in a directory? 2. how do i select a range of files, say 2nd-5th? I have done the following but I don't think the solution is a neat one. Query 1: select nth file - say 3rd file; #!/bin/bash touch foo1 foo2 foo3 foo4 foo5 foo6... (1 Reply)
Discussion started by: Muhammad Rahiz
1 Replies

6. Shell Programming and Scripting

regex to remove text before&&after comma chars

Hi, all: I have a question about "cleaning up" a huge file with regular expression(s) and sed: The init file goes like this: block1,blah-blah-blah-blah,numseries1,numseries2,numseries3,numseries4 block2,blah-blah-blah-blah-blah,numseries,numseries2,numseries3,numseries4 ...... (3 Replies)
Discussion started by: yomaya
3 Replies

7. UNIX for Dummies Questions & Answers

Search for & edit rows & columns in data file and pipe

Dear unix gurus, I have a data file with header information about a subject and also 3 columns of n rows of data on various items he owns. The data file looks something like this: adam peter blah blah blah blah blah blah car 01 30 200 02 31 400 03 57 121 .. .. .. .. .. .. n y... (8 Replies)
Discussion started by: tintin72
8 Replies

8. Shell Programming and Scripting

How do I search first&second string & copy all content between them to other file?

Hi All, How do I search first string & second string and copy all content between them from one file to another file? Please help me.. Thanks In Advance. Regards, Pankaj (12 Replies)
Discussion started by: pankajp
12 Replies

9. Shell Programming and Scripting

Advanced Search & Delete Text File

I have a file in which email messages are stored in. Every email is separated by by a ^Z character (Control-Z). I need to extract all emails after the 65,00th one to another file and delete them from the original file. Any suggests on accomplishing this? (2 Replies)
Discussion started by: maxcell
2 Replies

10. UNIX for Dummies Questions & Answers

Select records based on search criteria on first column

Hi All, I need to select only those records having a non zero record in the first column of a comma delimited file. Suppose my input file is having data like: "0","01/08/2005 07:11:15",1,1,"Created",,"01/08/2005" "0","01/08/2005 07:12:40",1,1,"Created",,"01/08/2005"... (2 Replies)
Discussion started by: shashi_kiran_v
2 Replies
Login or Register to Ask a Question