| Author |
Message |
Ed Morton *nix forums Guru
Joined: 20 Feb 2005
Posts: 1073
|
Posted: Thu Feb 10, 2005 10:15 pm Post subject:
Re: Segment file with EGREP?
|
|
|
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
|
Posted: Thu Feb 10, 2005 10:09 pm Post subject:
Re: Segment file with EGREP?
|
|
|
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
|
Posted: Thu Feb 10, 2005 8:32 pm Post subject:
Re: Segment file with EGREP?
|
|
|
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
|
Posted: Thu Feb 10, 2005 8:30 pm Post subject:
Re: Segment file with EGREP?
|
|
|
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
|
Posted: Thu Feb 10, 2005 8:29 pm Post subject:
Re: Segment file with EGREP?
|
|
|
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
|
Posted: Thu Feb 10, 2005 8:14 pm Post subject:
Re: Segment file with EGREP?
|
|
|
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
|
Posted: Thu Feb 10, 2005 7:53 pm Post subject:
Re: Segment file with EGREP?
|
|
|
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
|
Posted: Thu Feb 10, 2005 6:27 pm Post subject:
Re: Segment file with EGREP?
|
|
|
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
|
Posted: Thu Feb 10, 2005 6:21 pm Post subject:
Segment file with EGREP?
|
|
|
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 |
|
 |
|