Sponsored Content
Top Forums Shell Programming and Scripting How to extract the required lines? Post 302383288 by 14341 on Tuesday 29th of December 2009 06:35:14 AM
Old 12-29-2009
MySQL How to extract the required lines?

Hi Techies,

I got struck in middle of a problem. I have the following data whose format is:
Code:
a 1
a 2
a 3
a 4
b 1
b 2
b 3
b 4
c 1
c 2
c 3
c 4

I wanted the output from this to be:
Code:
a 3 
a 4
b 3
b 4
c 3
c 4

there can be any number of "a", "b","c","d"....might extened further to "e","f".........so on.

I wanted the last N (given 2 in the sample shown) lines from each "a","b","c"........

i had no clue where to start.

Can AWK do the job required ?
I donno but trying to learn it.

If anyone could give any idea, it would of great help.

Thank You,
14341
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

grep required pattern and next 2 or 3 lines

dear ones pl.kindly help me 1) how to print(grep) required pattern and following 2 or 3 lines. 2) grep required pattern(to print)+above 2 lines+below 2 or 3 lines.from a report file. ex: we have some report file kf askfjsk fksaj fk skf sjfksjd kff sjfkjs kf jskdjfklsd jfklsdf sdkfjsd fsd... (3 Replies)
Discussion started by: cvvsnm
3 Replies

2. Shell Programming and Scripting

To extract the required lines from a file

I have a files in a directory in this format data data data ---BEGIN CERT----- data data data ---END CERT ----- Now, I want to extract the lines starting from --BEGIN CERT-- and write the contents till the end of file into a new file.How can I do this for all the files in the... (1 Reply)
Discussion started by: sureshg
1 Replies

3. UNIX for Dummies Questions & Answers

How get only required lines & delete the rest of the lines in file

Hiiii I have a file which contains huge data as a.dat: PDE 1990 1 9 18 51 28.90 24.7500 95.2800 118.0 6.1 0.0 BURMA event name: 010990D time shift: 7.3000 half duration: 5.0000 latitude: 24.4200 longitude: 94.9500 depth: 129.6000 Mrr: ... (7 Replies)
Discussion started by: reva
7 Replies

4. Shell Programming and Scripting

Script required to extract a specific snippet from the entire file.

Hi, I have a file with the following structure. XXXXX........... YYYYY........... ................. .................. ZZZZZZ...... qwerty_start.............. .................. ................. .................. querty_end................ .............................. (1 Reply)
Discussion started by: abinash
1 Replies

5. Shell Programming and Scripting

Extract only required elements from XML.

Hi , I have an XML like this. <Request> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <version>v44</version><messageId>7247308192</messageId><timeToLive>72000000000</timeToLive> </Request>. I want to extract on version and messageId. As in my output... (13 Replies)
Discussion started by: chetan.c
13 Replies

6. Shell Programming and Scripting

Help with extract info if fulfill condition required

Input file (4 DATA record shown in this case): DATA AA0110 ACCESSION AA0110 VERSION AA0110 GI:157412239 FEATURES Location/Qualifiers length 1..1170 1..1700 /length="1170" position ... (5 Replies)
Discussion started by: perl_beginner
5 Replies

7. UNIX for Dummies Questions & Answers

Extract lines with specific words with addition 2 lines before and after

Dear all, Greetings. I would like to ask for your help to extract lines with specific words in addition 2 lines before and after these lines by using awk or sed. For example, the input file is: 1 ak1 abc1.0 1 ak2 abc1.0 1 ak3 abc1.0 1 ak4 abc1.0 1 ak5 abc1.1 1 ak6 abc1.1 1 ak7... (7 Replies)
Discussion started by: Amanda Low
7 Replies

8. Shell Programming and Scripting

Search for a pattern,extract value(s) from next line, extract lines having those extracted value(s)

I have hundreds of files to process. In each file I need to look for a pattern then extract value(s) from next line and then search for value(s) selected from point (2) in the same file at a specific position. HEADER ELECTRON TRANSPORT 18-MAR-98 1A7V TITLE CYTOCHROME... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

9. AIX

Grepping before and after lines for required string

Hi All, I am new to AIX unix . i need to grep for a pattern and if pattern is found then i need 3 before the pattern line found and 3 lines after the pattern found. (11 Replies)
Discussion started by: coolvibh
11 Replies

10. Shell Programming and Scripting

ksh sed - Extract specific lines with mulitple occurance of interesting lines

Data file example I look for primary and * to isolate the interesting slot number. slot=`sed '/^primary$/,/\*/!d' filename | tail -1 | sed s'/*//' | awk '{print $1" "$2}'` Now I want to get the Touch line for only the associate slot number, in this case, because the asterisk... (2 Replies)
Discussion started by: popeye
2 Replies
ConfigReader(3) 					User Contributed Perl Documentation					   ConfigReader(3)

NAME
ConfigReader - Read directives from a configuration file. DESCRIPTION
The ConfigReader library is a set of classes which reads directives from a configuration file. The library is completely object oriented, and it is envisioned that parsers for new styles of configuration files can be easily added. ConfigReader::Spec encapsulates a specification for configuration directives. You can specify which directives can be in the configuration file, aliases for the directive, whether the directive is required or has a default value, and how to parse the directive value. Here's an example of how one directive might be specified: required $spec 'HomePage', 'new URI::URL'; This defines a required directive called 'HomePage'. To parse the value from the configuration file, the URI::URL::new() method will be called with the string value as its argument. If the directive name is a simple string, it will be used both to refer to the directive in the Perl program, and as the name in the con- figuration file. You can also specify an alias by using an array ref. For example, suppose you wanted to use "index" as the name of the directive in the configuration file, but to avoid confusion with Perl's index() function you wanted to refer to the directive inside the program as the "file_index". This will do the trick: ['file_index', 'index'] You can specify any number of aliases for the directive: ['file_index', 'index', 'file_index', 'contents', ...] The parsing function or method is called to translate the value string from the configuration file into the value used by the program. It can be specified in several different ways: code ref static method object method undefined You can also specify a default value to be used if a directive is not specified in the configuration file. string value code ref undefined ConfigReader::Values stores a set of directive values that have been read from a configuration file. It stores a reference to an associ- ated Spec as a member variable. Separating the specification from the values makes it possible to use a single specification for multiple sets of values. ConfigReader::DirectiveStyle implements a reader for a common style of configuration file. It is a subclass of ConfigReader::Values. Directive names are followed by their value, one per line: HomePage http://www.w3.org/ Services /etc/services perl v5.8.2 1996-02-14 ConfigReader(3)
All times are GMT -4. The time now is 07:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy