Help with sed/awk for reverse search and print


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with sed/awk for reverse search and print
# 8  
Old 02-12-2011
Hi Yinyuemi,

Can you explain
Code:
awk '/\(/  {print "START"$0RT}' RS="START|O)"

so that I can modify it according to my real need.

---------- Post updated at 11:28 PM ---------- Previous update was at 10:47 PM ----------

well with some extra brackets it doesn't work.. closer example is..
Code:
START: ABDCJ
DSH
SDS(dfkhd)
END

START: jsdhjhjshgsj
gjdhi(dkfjd)
kjhg
END (VIO)

START: hshgsh
jfdjjd(fkhfuf)
dkfhdk(vjhfj)
END

START: jhdjghsj
AHDA(vjfkj)
FDJVsss
jdfjd
END (VIO)

START: DSKDJ
DFKDF
BVV(klfdjk)
END

START: kdfhf
djfhdj
kvh(gfjgkfj)
END

sfjhsdj
jhfdj(kfjgk)

---------- Post updated 02-12-11 at 01:47 AM ---------- Previous update was 02-11-11 at 11:28 PM ----------

Quote:
Originally Posted by kurumi
Code:
 $ ruby -0777 -ne '$_.split("END (VIO)").each {|x| puts x.split("START")[-1]}' file

doesn't work....

Last edited by Scott; 02-12-2011 at 06:08 AM.. Reason: Please use code tags
# 9  
Old 02-12-2011
Code:
awk '/\(V/ {print "START"$0RT}' RS="START|IO)"
START: jsdhjhjshgsj
gjdhi(dkfjd)
kjhg
END (VIO)
START: jhdjghsj
AHDA(vjfkj)
FDJVsss
jdfjd
END (VIO)

# 10  
Old 02-13-2011
Thanks, It worked. Can you do me favor by explaining the code.
# 11  
Old 02-13-2011
RS = "START|IO)" : using "START" or "IO)" as the record separator vairiable

RT is the value of RS.
Code:
/\(V/

: match "(V", here, it can also use "END (V" as a match pattern, which was used to specificlly print the content from "START" to "END (VIO)".

I'm not very good at english, so hopelly it can give you some clues.Smilie
This User Gave Thanks to yinyuemi For This Post:
# 12  
Old 02-13-2011
Thanks. It works for some 8k lines.. but it is not working for lines below 8k in a file.
# 13  
Old 02-13-2011
if the size of your file is not too large,try this:

Code:
tac |awk '/END \(VIO\)/,/START/' |tac

# 14  
Old 02-14-2011
file is big in the range of 16MB.. Is there any option so that
awk '/\(V/ {print "START"$0RT}' RS="START|IO)"

work for bigger file. It works only for few lines. Rest of the file remains untouched.

Last edited by pgbuddy; 02-14-2011 at 10:20 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to search output for a value and print

GOODNUMBERS="1 2 3 4 5 6 3 3 34 34 5 66 12" BADNUMBERS="7 3 12 5 66" for eachnum in `echo ${GOODNUMBERS}` do echo ${BADNUMBERS} | gawk -v threshold=${eachnum} '$1 != threshold' done what im trying to do with the above is, i want to print numbers that are in the GOODNUMBERS... (10 Replies)
Discussion started by: SkySmart
10 Replies

2. Shell Programming and Scripting

Awk/Sed: Search Pattern from file and Print

Hi, I want to search for patterns (from a file) in a file and print the line matching the patterns and the line before it. I have to search for 100s of patterns from a file. Any help with AWK or Sed. Thanks! (2 Replies)
Discussion started by: saint2006
2 Replies

3. Shell Programming and Scripting

awk search and print

I have a script where I need to use awk, go through some output, which is stored in a variable, and find a string Xms and Xmx and print the results, including the rest of that string. Example of string: ... (3 Replies)
Discussion started by: cbo0485
3 Replies

4. Shell Programming and Scripting

awk print second line after search string

I have multiple config files where I need to pull the ip address from loopback3. The format is the same in every file, the ip is the second line after interface loopback3. interface loopback2 loopback description router ID ip address 192.168.1.1 interface loopback3 loopback description... (3 Replies)
Discussion started by: numele
3 Replies

5. Shell Programming and Scripting

awk search column, print line

Hello. I've been banging my head against walls trying to search a comma delimited file, using awk. I'm trying to search a "column" for a specific parameter, if it matches, then I'd like to print the whole line. I've read in multiple texts: awk -F, '{ if ($4 == "string") print $0 }'... (2 Replies)
Discussion started by: Matthias03
2 Replies

6. Shell Programming and Scripting

How to use sed to search for string and Print previous two lines and current line

Hello, Can anybody help me to correct my sed syntax to find the string and print previous two lines and current line and next one line. i am using string as "testing" netstat -v | sed -n -e '/test/{x;2!p;g;$!N;p;D;}' -e h i am able to get the previous line current line next line but... (1 Reply)
Discussion started by: nmadhuhb
1 Replies

7. Shell Programming and Scripting

reverse search in awk script

Hi, I am new to awk. Actually I want to search a pattern A, when I get that line with pattern A then for one of the field of that line again I want search on that field (say pattern B)from start of the file. I am using awk. Is nested searching possible in awk? Please do the needful as... (4 Replies)
Discussion started by: id4forum
4 Replies

8. UNIX for Dummies Questions & Answers

awk search and print .doc extensions

Hello, I'm trying to grab all lines in a file that match the extension using the following command: awk '/.doc/' Input.csv > WordFiles.dat This works, but if a line contains "doc" it still prints the line. I want to print only the lines with ".doc" Can someone show how to pick up only... (1 Reply)
Discussion started by: orahi001
1 Replies

9. Shell Programming and Scripting

awk how to print if the search pattern contains speace

the data file is as below: > cat master.cnf /usr| location for usr|5 /src/ver1| version 1 |10 /src/ver2/log| ver 2 log |25 /src/sys/apps/log| Application log for sys|36 /src/sys/apps/conf| configuration location for app|45 /src/sys/apps/bin| binary location app|55my script is as below: ... (1 Reply)
Discussion started by: McLan
1 Replies

10. Shell Programming and Scripting

using awk to search and print output

suppose i have one file file A 18 24 30 35 38 45 55 Another file file B 08_46 A 16 V -0.36 0.23 E : 1.41 08_46 A 17 D -1.04 0.22 E : 0.84 08_46 A 18 Q -0.49 0.12 E : 0.06 08_46 A 19 G 0.50 0.14 E : 0.05 08_46 A 20 V ... (5 Replies)
Discussion started by: cdfd123
5 Replies
Login or Register to Ask a Question