Sponsored Content
Top Forums Shell Programming and Scripting Extract a pattern from multiple lines in a file Post 302753541 by Viernes on Wednesday 9th of January 2013 02:29:41 AM
Old 01-09-2013
Extract a pattern from multiple lines in a file

I have a file that has some lines starts with *
I want to get these lines, then get the word between "diac" and "lex".

ex.
file:
Code:
;;WORD AlAx
*0.942490 diac:Al>ax lex:>ax_1 bw:Al/DET+>ax/NOUN+ gloss:brother pos:noun prc3:0 prc2:0 prc1:0 prc0:Al_det per:na asp:na vox:na mod:na gen:m num:s stt:d cas:u enc0:0 rat:y source:spvar stem:>ax stemcat:N0F
--------------
;;WORD gyr
*0.983117 diac:gayoru lex:gayor_1 bw:+gayor/NOUN+u/CASE_DEF_NOM gloss:not;other pos:noun prc3:0 prc2:0 prc1:0 prc0:0 per:na asp:na vox:na mod:na gen:m num:s stt:c cas:n enc0:0 rat:y source:lex stem:gayor stemcat:N

Desired output:
Code:
Al>ax
gayoru


I am not sure if I should use sed or grep. Have been trying for a while, with this command:
Code:
grep -A 3 -o ':.* lex:' boo

I get:
Code:
:Al>ax lex:

Thank you in advance!
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

extract x lines after a pattern - place each result in separate file

Hi all, I have many files that have 1 or more occurrences of the information I want. There are two distinct sets of information. I want get this info and place each occurrence in its own file. The 3 lines before one set are this grid 00 01 02 16 17 18 **40 lines of code I want to... (5 Replies)
Discussion started by: gobi
5 Replies

2. UNIX for Dummies Questions & Answers

Help please, extract multiple lines from a text file

Hi all, I need to extract lines between the lines 'RD' and 'QA' from a text file (following). there are more that one of such pattern in the file and I need to extract all of them. however, the number of lines between them is varied in the file. Therefore, I can not just use 'grep -A' command.... (6 Replies)
Discussion started by: johnshembb
6 Replies

3. Shell Programming and Scripting

Extract strings from multiple lines into one file -

input file Desired csv output gc_type, date/time, milli secs af, Mar 17 13:09:04 2011, 144.596 af, Mar 20 00:37:37 2011, 144.242 af, ar 20 21:30:59 2011, 108.518 Hi All, Any help in acheiving the above would be appreciated. I would like to parse through lines within one file and... (5 Replies)
Discussion started by: satish.vampire
5 Replies

4. Shell Programming and Scripting

Extract strings from multiple lines into one csv file

Hi all, Please go through my requirement. I have a log file in the location /opt/WebSphere61/AppServer/profiles/EMQbatchprofile/logs/EMQbatch This file contains the follwing pattern data <af type="tenured" id="42" timestamp="May 14 13:44:13 2011" intervalms="955.624"> <minimum... (8 Replies)
Discussion started by: satish.vampire
8 Replies

5. UNIX for Dummies Questions & Answers

print multiple lines from text file based on pattern list

I have a text file with a list of items/patterns: ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig12238 ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig34624... (1 Reply)
Discussion started by: Oyster
1 Replies

6. 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

7. Shell Programming and Scripting

Extract lines that match a pattern

Hi all, I got a file that contains the following content, Actually it is a part of the file content, Installing XYZ XYZA Image, API 18, revision 2 Unzipping XYZ XYZA Image, API 18, revision 2 (1%) Unzipping XYZ XYZA Image, API 18, revision 2 (96%) Unzipping XYZ XYZA Image, API 18,... (7 Replies)
Discussion started by: Kashyap
7 Replies

8. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

9. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies
LEX(1)							      General Commands Manual							    LEX(1)

NAME
lex - generator of lexical analysis programs SYNOPSIS
lex [ -tvfn ] [ file ] ... DESCRIPTION
Lex generates programs to be used in simple lexical analyis of text. The input files (standard input default) contain regular expressions to be searched for, and actions written in C to be executed when expressions are found. A C source program, 'lex.yy.c' is generated, to be compiled thus: cc lex.yy.c -ll This program, when run, copies unrecognized portions of the input to the output, and executes the associated C action for each regular expression that is recognized. The options have the following meanings. -t Place the result on the standard output instead of in file "lex.yy.c". -v Print a one-line summary of statistics of the generated analyzer. -n Opposite of -v; -n is default. -f "Faster" compilation: don't bother to pack the resulting tables; limited to small programs. EXAMPLE
lex lexcommands would draw lex instructions from the file lexcommands, and place the output in lex.yy.c %% [A-Z] putchar(yytext[0]+'a'-'A'); [ ]+$ ; [ ]+ putchar(' '); is an example of a lex program that would be put into a lex command file. This program converts upper case to lower, removes blanks at the end of lines, and replaces multiple blanks by single blanks. SEE ALSO
yacc(1), sed(1) M. E. Lesk and E. Schmidt, LEX - Lexical Analyzer Generator 7th Edition April 14, 1986 LEX(1)
All times are GMT -4. The time now is 11:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy