Sponsored Content
Full Discussion: finding the nth match
Top Forums UNIX for Dummies Questions & Answers finding the nth match Post 302530970 by countryStyle on Wednesday 15th of June 2011 01:09:55 PM
Old 06-15-2011
Quote:
Originally Posted by Corona688
If you'd posted your data you could have had an answer an hour ago... I'll ignore the personal slur and explain a little more.

grep considers no logic but patterns when matching lines. It doesn't remember anything about previous lines and has no expression to carry information from previous lines across to next ones. The awk language is much better suited, since it deals with lines/patterns and has variables plus logical expressions. (I think sed does too in a fashion, but its expression syntax is rather convoluted. awk gives you straightforward variables with names, and straightforward expressions with if/else.) I'm only asking you for your data. I'm not even the first one.

If you really want I'll give you a ridiculous solution like grep pattern file | tail -n +5 | head -n 1 to get match 4 which is of course a very silly solution and might not work in Solaris. A less silly solution would be nawk '/pattern/ {} NR=2' but you asked for grep, this may not suit your needs, and there may be even more efficient ways to deal with the data depending on what it actually is and what you're trying to do.
You slur...I slur back....that is how that first part went......anyways...

See....you did not need data to answer and there was no problem adding on the excellent commentary/lead about awk. I know a lot of people often ask for the answer to their specific issue and want YOU the other poster to do all the work for them (sometimes very practical). I am still at the general question looking to get more of a clue phase but if you want to do all my work for me let me know...I am certain you can do it fast.

I have something to work with and can make some progress (fingers crossed).

Thank you so much: )

---------- Post updated at 12:09 PM ---------- Previous update was at 12:03 PM ----------

had to change the line for Solaris:

grep pattern file | tail +5 | head -1

I am not working with large files here and performance is not an issue......

The line is easy to use and works in the Bash shell so....why is this a silly solution, performance, crossplatform issues?

thanks again.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Finding nth occurrence in line and replacing it

Hi, I have several files with data that have to be imported to a database. These files contain records with separator characters. Some records are corrupt (2 separators are missing) and I need to correct them prior to importing them into the db. Example: ... (5 Replies)
Discussion started by: stresing
5 Replies

2. Shell Programming and Scripting

Getting filename for Nth line pattern match

Hi, I have many scripts in particular directory. And few of the scripts have exit 0 in second line. Now i wanted to list out the scripts name which has the exit 0 in its second line I tried many options , but i can not get the filename along with the nth line pattern match :mad:. Can anyone... (14 Replies)
Discussion started by: puni
14 Replies

3. UNIX for Dummies Questions & Answers

Finding nth line across multiple files

I have several files (around 50) that have the similar format. I need to extract the 5th line from every file and output that into a text file. So far, I have been able to figure out how to do it for a single file: $ awk 'NR==5' text1.txt > results.txt OR $ sed -n '5p' text1.txt > results.txt... (6 Replies)
Discussion started by: oriqin
6 Replies

4. Shell Programming and Scripting

Finding Nth Column

Please help me how can I display every nth field present in a "|" delimited file. Ex: If a have a file with data as a|b|c|d|e|f|g|h|k|l|m|n I want to display every 3rd feild which means the output should be c f k n Please help me. (1 Reply)
Discussion started by: ngkumar
1 Replies

5. UNIX for Dummies Questions & Answers

Printing nth and n+1th line after a pattern match

Hi , I want to print the nth and n+1 lines from a file once it gets a pattern match. For eg: aaa bbb ccc ddd gh jjjj If I find a match for bbb then I need to print bbb as well as 3rd and 4th line from the match.. Please help..Is it possible to get a command using sed :) (6 Replies)
Discussion started by: saj
6 Replies

6. Answers to Frequently Asked Questions

Finding the nth Particular Week in a Month – shell script

I see lot of request posted in internet to find out the day of nth week in a Month. example: what is the date of 3rd Sunday in October What is the date of 2nd Friday in June 2012 what is the date of 4th Saturday in January 2011..etc.. The below shell script is used to find out the... (1 Reply)
Discussion started by: itkamaraj
1 Replies

7. Shell Programming and Scripting

Problem getting Nth match in sed

Hi all, I'm trying to create a sed command to get the Nth instance of an XML tag in a string, but thus far I can only ever seem to get the last one. Given an XML string: <Wrap><GrayLevel>a</GrayLevel><GrayLevel>b</GrayLevel></Wrap> I tried to do this on the command line to get each... (7 Replies)
Discussion started by: Zel2008
7 Replies

8. Shell Programming and Scripting

How to display when nth line match a pattern?

Hi All, I have sample of listing as following Database 2 entry: Database alias = PXRES Database name = PXRES Local database directory = /db2/data1/db2phnx Database release level = d.00 Comment ... (3 Replies)
Discussion started by: ckwan
3 Replies

9. Shell Programming and Scripting

sed : replace Nth match in a file

I have a situation where a file "config.txt" looks like this Servername: OS: Serername: OS: Servername: OS: .... .... ... Servername: OS: looking for the sed syntax to replace the "Nth" occurrence of Servername (i would apply the same logic to OS as well), want to replace the Nth... (4 Replies)
Discussion started by: alldbest
4 Replies

10. AIX

Print nth previous line after match

Please help me print nth line after match awk or sed one line command. (3 Replies)
Discussion started by: sushma123
3 Replies
SOAP::Deserializer(3pm) 				User Contributed Perl Documentation				   SOAP::Deserializer(3pm)

NAME
SOAP::Deserializer - the means by which the toolkit manages the conversion of XML into an object manageable by a developer DESCRIPTION
SOAP::Deserializer provides the means by which incoming XML is decoded into a Perl data structure. METHODS
context This provides access to the calling context of "SOAP::Deserializer". In a client side context the often means a reference to an instance of SOAP::Lite. In a server side context this means a reference to a SOAP::Server instance. EXAMPLES
DESERIALIZING RAW XML INTO A SOAP::SOM OBJECT A useful utility for SOAP::Deserializer is for parsing raw XML documents or fragments into a SOAP::SOM object. SOAP::Lite developers use this technique to write unit tests for the SOAP::Lite module itself. It is a lot more efficient for testing aspects of the toolkit than generating client calls over the network. This is a perfect way for developers to write unit tests for their custom data types for example. Here is an example of how raw XML content can be parsed into a SOAP::SOM object by using SOAP::Deserializer: $xml = <<END_XML; <foo> <person> <foo>123</foo> <foo>456</foo> </person> <person> <foo>789</foo> <foo>012</foo> </person> </foo> END_XML my $som = SOAP::Deserializer->deserialize($xml); COPYRIGHT
Copyright (C) 2000-2004 Paul Kulchenko. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. AUTHORS
Byrne Reese (byrne@majordojo.com) perl v5.12.4 2010-06-03 SOAP::Deserializer(3pm)
All times are GMT -4. The time now is 04:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy