[PLUG] File content modification

Nandan Marathe nrmarathe at gmail.com
Tue Aug 3 20:38:26 IST 2010


On Tue, Aug 3, 2010 at 9:29 AM, Gaurav Pant <gauravggs at gmail.com> wrote:

> On Tue, Aug 3, 2010 at 9:10 AM, Gaurav Pant <gauravggs at gmail.com> wrote:
> > 2010/8/3 शंतनू (Shantanoo) <shantanoo at gmail.com>:
> >> On Sat, Jul 31, 2010 at 12:32, Shreerang Patwardhan
> >> <patwardhan.shreerang at gmail.com> wrote:
> >>> Hello all,
> >>>     I have a file with contents in the following manner:
> >>> 10001_abc_county
> >>> 10003_abc_xyz_county
> >>> 10005_abc_pqr_xyz_county
> >>>
> >>> Each entry is on a new line and each line begins with a number and ends
> with
> >>> the word county!
>
> Can be done with awk too..
>
>  cat file  | awk -F'_' '{ for(i=2;i<NF;i++) printf("%s", $i); printf("\n")
> }'
>
> --dexter
>
> on the topic of regular expressions. I have been trying to find an easy way
to match
patterns which span over a few lines. For instance I have a large file which
has snippets like
/begin/
sadjkhasdkj
asjhsdfkjf
... bla bla
/end/

How do I match the number of times this pattern occurs in the file.
following are the possibilities:
1) pattern always spans over a fixed number of lines ( lets say 4)
2) pattern may span over multiple number of lines
3) there are no nested such patterns .

Sed allows some sort of multiline matching, but it is quite limited and only
works in the option 1.
for variable length patterns i am yet to find an easy tool than writing a
perl script to first mark line numbers
of the first pattern and then the second one and extract the lines.

regards,
Nandan

> _______________________________________
> Pune GNU/Linux Users Group Mailing List
>



More information about the Plug-mail mailing list