Sponsored Content
Full Discussion: finding the nth match
Top Forums UNIX for Dummies Questions & Answers finding the nth match Post 302530984 by Corona688 on Wednesday 15th of June 2011 02:16:58 PM
Old 06-15-2011
Quote:
Originally Posted by countryStyle
See....you did not need data to answer and there was no problem adding on the excellent commentary/lead about awk.
If I lucked out into something that did exactly what you wanted the very first try, then I lucked out. Getting people to explain what they really want can be as difficult as -- well -- as difficult as getting you to post your data.

Simple questions shouldn't always be taken at face value, either
Quote:
Originally Posted by qdb.us
<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"
<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers
So frequent posters here develop some habitual questions. 1) Post your OS (thank you for that), 2) Post your data! It makes things a lot smoother all around.

Quote:
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.
You know the saying, a bird in the hand is worth two in the bush? It doesn't have to be either/or. I can make a simple example that works with your data without doing all your work for you, which will look more straighforward than one for random data I had lying around.
Quote:
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?
Running one program instead of two is much better, and if you can avoid any programs, that's better yet! External programs take time to start and stop, even for tiny files -- especially for tiny files, where most of the time would be spent loading/quitting instead of work. And pipes can waste time communicating with each other (grep reads, writes, tail reads, writes, head reads, writes.) Both of these can add up faster than you'd expect. One of my first shell programming experiments was a text linewrapper that ran at the blazing speed of one kilobyte per second.

This is also why I'm curious what your program actually is and how you're using this 'get line x' code, because if grep | tail | head is your way of loading individual lines of data from file, you might want to ask about better ways to organize your program.
 

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
QUIZ(6) 							 BSD Games Manual							   QUIZ(6)

NAME
quiz -- random knowledge tests SYNOPSIS
quiz [-t] [-i file] [question answer] DESCRIPTION
The quiz utility tests your knowledge of random facts. It has a database of subjects from which you can choose. With no arguments, quiz displays the list of available subjects. The options are as follows: -t Use tutorial mode, in which questions are repeated later if you didn't get them right the first time, and new questions are presented less frequently to help you learn the older ones. -i Specify an alternative index file. Subjects are divided into categories. You can pick any two categories from the same subject. quiz will ask questions from the first cate- gory and it expects answers from the second category. For example, the command ``quiz victim killer'' asks questions which are the names of victims, and expects you to answer with the cause of their untimely demise, whereas the command ``quiz killer victim'' works the other way around. If you get the answer wrong, quiz lets you try again. To see the right answer, enter a blank line. Index and Data File Syntax The index and data files have a similar syntax. Lines in them consist of several categories separated by colons. The categories are regular expressions formed using the following meta-characters: pat|pat alternative patterns {pat} optional pattern [pat] delimiters, as in pat[pat|pat]pat In an index file, each line represents a subject. The first category in each subject is the pathname of the data file for the subject. The remaining categories are regular expressions for the titles of each category in the subject. In data files, each line represents a question/answer set. Each category is the information for the question/answer for that category. The backslash character (``'') is used to quote syntactically significant characters, or at the end of a line to signify that a continuation line follows. If either a question or its answer is empty, quiz will refrain from asking it. FILES
/usr/share/games/bsdgames/quiz The default index and data files. BUGS
quiz is pretty cynical about certain subjects. BSD
May 31, 1993 BSD
All times are GMT -4. The time now is 12:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy