Sponsored Content
Top Forums Shell Programming and Scripting How to extract a paragraph containing a given string? Post 302976422 by delphys on Wednesday 29th of June 2016 07:22:47 AM
Old 06-29-2016
How to extract a paragraph containing a given string?

Hello:

Have a very annoying problem:

Need to extract paragraphs with a specific string in them from a very large file
with a repeating record separator.

Example data: a file called test.out

Code:
CREATE VIEW view1
AS something
FROM table1 ,table2 as A, table3 (something FROM table4)
FROM table5, table6
USING file1
;
CREATE VIEW view1
FROM table1 ,table2 ,table6 ,table9
something
something
FROM table5 ,table (something FROM table4 ,table5(this is something FROM table8)
USING file2
;
CREATE VIEW view1
FROM table1 ,table2 ,table6 ,table8
something
something
FROM table5 ,table (something FROM table4 ,table5(this is something FROM table8)
USING file2
;
CREATE VIEW view1
FROM table1 ,table2 ,table6 ,table7
something
something
FROM table5 ,table7 (something FROM table4 ,table5(this is something FROM table8)
USING file2
;
CREATE VIEW view1
FROM table1 ,table2 ,table6 ,table6
something
something
FROM table5 ,table (something FROM table4 ,table5(this is something FROM table8)
USING file2
;

If I want to extract a paragraph containing the string "table7"

Code:
 
awk -v RS="CREATE VIEW" '/table7/' test.out

 view1
FROM table1 ,table2 ,table6 ,table7
something
something
FROM table5 ,table7 (something FROM table4 ,table5(this is something FROM table8)
USING file2
;

The problem is that the RS variable always cuts out the RS value itself, as you can see..

How do I tell awk to print the RS value too .. ??

Thnx in advance.


Moderator's Comments:
Mod Comment Thanks for trying to use the required tags, but please use CODE tags instead of ICODE tags.

Last edited by RudiC; 06-29-2016 at 08:26 AM.. Reason: Changed ICODE to CODE tags.
 

10 More Discussions You Might Find Interesting

1. Linux

Extract a paragraph

Hi , Unix.com has been life saver for me I admit :) I am trying to extract a paragraph based on matching pattern "CREATE TABLE " from a ddl file . The paragraphs are seperated by blank line . Input file is #cat zip.20080604.sql1 CONNECT TO TST103 SET SESSION_USER OPSDM002 ... (2 Replies)
Discussion started by: capri_drm
2 Replies

2. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

3. Shell Programming and Scripting

Search for a particular string in a paragraph in a text

Hi all, i'm new to this community. I am trying to write a script which will fetch ftp completion time of a file from a paragraph of a big text file ( which contains multiple paragraphs) . Each paragraph will have ftp details.. Now I dont know how to fetch process time within a paragraph of... (3 Replies)
Discussion started by: prachiagra
3 Replies

4. UNIX for Dummies Questions & Answers

Output text from 1st paragraph in file w/ a specific string through last paragraph of file w/ string

Hi, I'm trying to output all text from the first paragraph in a file that contains a specific string through the last paragraph in that file that contains that string. Previously, I was outputting just each paragraph with that search string with: cat in_file | nawk '{RS=""; FS="\n";... (2 Replies)
Discussion started by: carpenn
2 Replies

5. Shell Programming and Scripting

How to extract multiple line in a paragraph? Please help.

Hi all, The following lines are taken from a long paragraph: Labels of output orbitals: RY* RY* RY* RY* RY* RY* 1\1\GINC-COMPUTE-1-3\SP\UB3LYP\6-31G\C2H5Cr1O1(1+,5)\LIUZHEN\19-Jan-20 10\0\\# ub3lyp/6-31G pop=(nbo,savenbo) gfprint\\E101GECP\\1,5\O,0,-1.7 ... (1 Reply)
Discussion started by: liuzhencc
1 Replies

6. Shell Programming and Scripting

to extract string from main string and string comparison

continuing from my previous post, whose link is given below as a reference https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569 consider there is create table commands in a file for eg: CREATE TABLE `Blahblahblah` ( `id` int(11) NOT NULL... (2 Replies)
Discussion started by: vivek d r
2 Replies

7. Shell Programming and Scripting

Search String and extract few lines under the searched string

Need Assistance in shell programming... I have a huge file which has multiple stations and i wanted to search particular station and extract few lines from it and the rest is not needed Bold letters are the stations . The whole file has multiple stations . Below example i wanted to search... (4 Replies)
Discussion started by: ajayram_arya
4 Replies

8. Shell Programming and Scripting

How to extract every repeated string between two specific string?

Hello guys, I have problem with hpux shell script. I have one big text file that contains like SOH bla bla bla bla bla bla ETX SOH bla bla bla ETX SOH bla bla bla ETX What I need to do is save first SOH*BLA into file1.txt, save second SOH*BLA into file2.txt and so on.... (17 Replies)
Discussion started by: sembii
17 Replies

9. UNIX for Dummies Questions & Answers

Extract paragraph that contains a value x<-30

I am using OSX. I have a multi-mol2 file (text file with coordinates and info for several molecules). An example of two molecules in the file is given below for molecule1 and molecule 2. The total file contains >50,000 molecules. I would like to extract out and write to another file only the... (2 Replies)
Discussion started by: Egy
2 Replies

10. Shell Programming and Scripting

Bash script to extract paragraph with globs in it

Hi, Its been a long time since I have used Bash to write a script so am really struggling here. Need the gurus to help me out. uname -a Linux lxserv01 2.6.18-417.el5 i have a text file with blocks of code written in a similar manner ******* BEGIN MESSAGE ******* Station /... (12 Replies)
Discussion started by: dsid
12 Replies
Pod::Index(3pm) 					User Contributed Perl Documentation					   Pod::Index(3pm)

NAME
Pod::Index - Index and search PODs using X<> entries. SYNOPSIS
### to create an index: use Pod::Index::Builder; my $p = Pod::Index::Builder->new; for my $file (@ARGV) { $p->parse_from_file($file); } $p->print_index("index.txt"); ### to search for a keyword in the index: use Pod::Index::Search; my $q = Pod::Index::Search->new( filename => 'index.txt', ); my @results = $q->search('getprotobyname'); for my $r (@results) { printf "%s %s ", $r->podname, $r->line; print $r->pod; } DESCRIPTION
The Pod-Index distribution includes various modules for indexing and searching POD that is appropriately marked with X<> POD codes. "Pod::Index", as a module, does nothing. Everything is done by Pod::Index::Builder, Pod::Index::Search, and other helper modules. This document discusses some of the general issues with POD indexing; specifically, the recommended conventions for the use of X<> codes. BACKGROUND
The little-known (or at least little-used) X<> formatting code is described in perlpod: "X<topic name>" -- an index entry This is ignored by most formatters, but some may use it for build- ing indexes. It always renders as empty-string. Example: "X<abso- lutizing relative URLs>" CONVENTIONS FOR THE USE OF X<;> CODES Placement of the X<> entries First, a definition. By "scope", I mean the part of the document that is deemed relevant to an index entry, and that may be extracted and shown in isolation by a processing or display tool. For example, perldoc -f considers the scope of a function to end at the beginning of the next =item, or at the end of the enclosing =over. The X<> entries should be added at the end of a command or textblock paragraph (verbatim paragraphs are excluded). The scope of the index entry starts at the beginning of the paragraph to which it was attached; the end of the scope depends on the command type: 1) if the X<> is at the end of a textblock, the scope is that paragraph and zero or more verbatim paragraphs immediately following it. 2) if the X<> is at the end of a command paragraph, it depends on the type of command: =head1, head2, etc. The scope ends right before the next heading with equal or higher level. That is, a =head1 ends at the next =head1, and a =head2 ends at the next =head2 or =head1. =item The scope ends right before the next =item, or the =back that terminates the containing list. Note: "empty" items are not counted for terminating scopes, to allow for cases where multiple =items head a block of text. For example, =item function X<function> X<otherfunction> =item otherfunction C<function> and C<otherfunction> do the same thing, even if they have different names... =item lemonade Here the scope of the X<function> and X<otherfunction> entries starts with "=item function", and ends right before "=item lemonade". 3) other command paragraphs, such as =back, =over, =begin, =end, and =for should not be used for attaching X<> entries. Content of the X<> entry. o It should contain plain text without further formatting codes (with the possible exception of E<>). o It should be in lowercase, unless caps are required due to case-sensitivity or correctness. o Non-word characters are allowed, so one can list things like operators and special variables. o Use of synonyms is encouraged, to make things easier to find. o To be consistent, words should be normalized to the singular whenever possible. For example, use X<operator> instead of X<operators>. o The use of a comma in an index entry has a special meaning: it separates levels of hierarchy (or namespaces), as a way of classifying entries in more specific ways. For example, "X<operator, logical>", or "X<operator, logical, xor>". This information may be used by processing programs to arrange the entries, or for listing results when a user searches for a namespace that contains several entries. o There's no limitation as to the number of times that a given entry can appear in a document or collection of documents. That is, it is not an error to have X<whatever> appear twice in the same file. VERSION
0.14 SEE ALSO
Pod::Index::Builder, Pod::Index::Search, Pod::Index::Entry, perlpod AUTHOR
Ivan Tubert-Brohman <itub@cpan.org> COPYRIGHT
Copyright (c) 2005 Ivan Tubert-Brohman. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.0 2005-10-16 Pod::Index(3pm)
All times are GMT -4. The time now is 10:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy