Results 1 to 10 of 11
Hi All i have a text in a file i have to grep for the second occurencre (DESCRIPTION) of the file and and append to a file
can you please ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-05-2012 #1Just Joined!
- Join Date
- Nov 2012
- Posts
- 4
Grep for the second occurence in the file
Hi All i have a text in a file i have to grep for the second occurencre (DESCRIPTION) of the file and and append to a file
can you please help
DESCRIPTION
Sed is a stream editor. A stream editor is used to perform basic text
transformations on an input stream (a file or input from a pipeline).
While in some ways similar to an editor which permits scripted edits
(such as ed), sed works by making only one pass over the input(s), and
is consequently more efficient. But it is sedās ability to filter text
in a pipeline which particularly distinguishes it from other types of
editors.
DESCRIPTION
Sed is a stream editor. A stream editor is used to perform basic text
transformations on an input stream (a file or input from a pipeline).
While in some ways similar to an editor which permits scripted edits
(such as ed), sed works by making only one pass over the input(s), and
is consequently more efficient. But it is sedās ability to filter text
in a pipeline which particularly distinguishes it from other types of
editors.
- 11-05-2012 #2Linux Newbie
- Join Date
- Nov 2012
- Posts
- 134
hi,
I suppose you also want the text below the pattern, right?
then, grep wil not help, but sed will!
- 11-05-2012 #3Just Joined!
- Join Date
- Nov 2012
- Location
- Romania
- Posts
- 4
Hi, do you know if your description is in one line?
- 11-05-2012 #4Just Joined!
- Join Date
- Nov 2012
- Posts
- 4
Yes i want to grep the below text after the DESCRIPTION to the last line "editors." yes it sin the same file
- 11-05-2012 #5Just Joined!
- Join Date
- Nov 2012
- Posts
- 4
No its not in one line
Example : DESCRIPTION Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline).While in some ways similar to an editor which permits
DESCRIPTION sed works by making only one pass over the input(s), andis consequently more efficient. But it is sedās ability to filter text in a pipeline
- 11-05-2012 #6
Im not sure if I understand this correctly or not. But I think this might work;
Code:grep -v ^DESCRIPTION
- 11-05-2012 #7Linux Newbie
- Join Date
- Nov 2012
- Posts
- 134
did some search about "sed print last occurrence" and get an answer:
Code:$ cat UrFile DESCRIPTION Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sedās ability to filter text in a pipeline which particularly distinguishes it from other types of editors. DESCRIPTION last Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sedās ability to filter text in a pipeline which particularly distinguishes it from other types of editors. $ sed -n 'H; /^DESCRIPTION/h; ${g;p;}' UrFile DESCRIPTION last Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sedās ability to filter text in a pipeline which particularly distinguishes it from other types of editors.
- 11-05-2012 #8Just Joined!
- Join Date
- Nov 2012
- Location
- Romania
- Posts
- 4
hi again, try this:
awk '/DESCRIPTION/{n++}{print >"output" n ".txt" }' YOURFILE
this will generate a file for each description that will find untill the next pattern will be found, so if you have
$: cat YOURFILE
DESCRIPTION
This
is
a
nice
description
DESCRIPTION
Indeed
a
nice
row
here
when you will execute the command you will get
output1.txt with
DESCRIPTION
This
is
a
nice
description
and output2.txt with
DESCRIPTION
Indeed
a
nice
row
here
Hope this help
- 11-05-2012 #9Just Joined!
- Join Date
- Nov 2012
- Posts
- 4
Thank you Watale & covidium for getting me what i was looking for . Thanks a lot for your help
How can i grep until gawk
suppose from the below file output.xt
Desired o/p :Code:DESCRIPTION last Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sedās ability to filter text in a pipeline which particularly distinguishes it from other types of editors. gawk - pattern scanning and processing language DESCRIPTION Gawk is the GNU Projectās implementation of the AWK programming lan- guage. It conforms to the definition of the language in the POSIX 1003.2 Command Language And Utilities Standard. This version in turn is based on the description in The AWK Programming Language, by Aho, Kernighan, and Weinberger, with the additional features found in the System V Release 4 version of UNIX awk. Gawk also provides more recent Bell Laboratories awk extensions, and a number of GNU-specific exten- sions.
Code:DESCRIPTION last Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sedās ability to filter text in a pipeline which particularly distinguishes it from other types of editors.
Last edited by atreyu; 11-07-2012 at 02:19 AM. Reason: added code tags for readability
- 11-07-2012 #10Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,664
Hello and welcome!
You can use awk's range operators, which are basically two regexps. Here is an example:
If your text really does not have the "last" in "DESCRIPTION last", then we might have to get trickier...Code:cat output.txt|awk '/DESCRIPTION last/,/gawk/'
Last edited by atreyu; 11-07-2012 at 02:22 AM. Reason: typo


Reply With Quote
