niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » shell
Segment file with EGREP?
Post new topic   Reply to topic Page 1 of 1 [9 Posts] View previous topic :: View next topic
Author Message
Ed Morton
*nix forums Guru


Joined: 20 Feb 2005
Posts: 1073

PostPosted: Thu Feb 10, 2005 10:15 pm    Post subject: Re: Segment file with EGREP? Reply with quote

david wrote:
Quote:
still getting the too many files error...

How would you use csplit to segment a text file by each 100th
occurrence of a string of characters?


You can't. I assume the "too many file" is from awk. Show us your code
now you've updated it as I suggested and tell us which version of awk
you're running.

Ed.
Back to top
david
*nix forums beginner


Joined: 15 Apr 2005
Posts: 8

PostPosted: Thu Feb 10, 2005 10:09 pm    Post subject: Re: Segment file with EGREP? Reply with quote

still getting the too many files error...

How would you use csplit to segment a text file by each 100th
occurrence of a string of characters?
Back to top
Ed Morton
*nix forums Guru


Joined: 20 Feb 2005
Posts: 1073

PostPosted: Thu Feb 10, 2005 8:32 pm    Post subject: Re: Segment file with EGREP? Reply with quote

david wrote:

Quote:
Hi Ed-

Thanks for the quick response. I don't need to use egrep. I was just
under the impression that it was the best method.

I tried using your method, but awk keeps on bombing out due to the
following error:

awk: too many output files 10
record number 1000

This is what I have:

awk '/"=============================="/
{c++; if (c==100) {fn++; c=0}}
{print > filename_segments"."fn}' fn=0 filename


filename_segments is an undefined variable, so this will just generate a
bunch of hidden files (i.e. ones that start with "."). he version I
posted used your original file name as a base. If you want to use
"filename_segments" as a base, then put it in the double quotes around ".".

As for too many files, try throwing in a "close()" within the "if"
clause to close the previous one before you open a new one.

By the way, if you're not using it already - I recommend using "gawk"
as your awk.

Ed.
Back to top
Bill Marcum
*nix forums Guru


Joined: 28 Mar 2005
Posts: 1264

PostPosted: Thu Feb 10, 2005 8:30 pm    Post subject: Re: Segment file with EGREP? Reply with quote

On 10 Feb 2005 11:21:18 -0800, david
<yeodavid@gmail.com> wrote:
Quote:
I have a text file with sections of the file divided by a string of
characters, i.e.

***********************************

How would I use egrep to segment the file for every 100th occurence of
the "***********************************" string?

Thank you in advance.

man csplit
Back to top
Ed Morton
*nix forums Guru


Joined: 20 Feb 2005
Posts: 1073

PostPosted: Thu Feb 10, 2005 8:29 pm    Post subject: Re: Segment file with EGREP? Reply with quote

david wrote:

Quote:
Will this print only those lines that match the string? I also need
the sections between these strings to be printed.


No, it'll print the whole file, segmented.

Ed.
Back to top
david
*nix forums beginner


Joined: 15 Apr 2005
Posts: 8

PostPosted: Thu Feb 10, 2005 8:14 pm    Post subject: Re: Segment file with EGREP? Reply with quote

Will this print only those lines that match the string? I also need
the sections between these strings to be printed.
Back to top
david
*nix forums beginner


Joined: 15 Apr 2005
Posts: 8

PostPosted: Thu Feb 10, 2005 7:53 pm    Post subject: Re: Segment file with EGREP? Reply with quote

Hi Ed-

Thanks for the quick response. I don't need to use egrep. I was just
under the impression that it was the best method.

I tried using your method, but awk keeps on bombing out due to the
following error:

awk: too many output files 10
record number 1000

This is what I have:

awk '/"=============================="/
{c++; if (c==100) {fn++; c=0}}
{print > filename_segments"."fn}' fn=0 filename
Back to top
Ed Morton
*nix forums Guru


Joined: 20 Feb 2005
Posts: 1073

PostPosted: Thu Feb 10, 2005 6:27 pm    Post subject: Re: Segment file with EGREP? Reply with quote

david wrote:
Quote:
I have a text file with sections of the file divided by a string of
characters, i.e.

***********************************

How would I use egrep to segment the file for every 100th occurence of
the "***********************************" string?

Thank you in advance.


awk could do this easily, e.g. (untested):

awk '/***********************************/{c++;if (c==100){fn++;c=0}}
{print > FILENAME "." fn}' fn=0 file

Do you really need to use egrep?

Ed.
Back to top
david
*nix forums beginner


Joined: 15 Apr 2005
Posts: 8

PostPosted: Thu Feb 10, 2005 6:21 pm    Post subject: Segment file with EGREP? Reply with quote

I have a text file with sections of the file divided by a string of
characters, i.e.

***********************************

How would I use egrep to segment the file for every 100th occurence of
the "***********************************" string?

Thank you in advance.
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [9 Posts] View previous topic :: View next topic
The time now is Fri Jan 09, 2009 12:50 am | All times are GMT
navigation Forum index » Programming » shell
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Running php file everyday on scheduled time sachin PHP 1 Fri Jul 21, 2006 12:49 pm
No new posts Regarding thesaurus iso file Srikanth modules 0 Fri Jul 21, 2006 10:42 am
No new posts how can i get a file descriptor not used? mars system 0 Fri Jul 21, 2006 7:41 am
No new posts small GTK "Open file" dialog David Siroky Debian 0 Fri Jul 21, 2006 7:30 am
No new posts Trouble Declaring 3D Array in Header File free2klim C++ 1 Fri Jul 21, 2006 4:07 am

Upvc Doors | Repair Bad Credit | Bankruptcy | Debt Consolidation | Mortgages
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.3529s ][ Queries: 20 (0.2272s) ][ GZIP on - Debug on ]