Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

csplit problem 1

Status
Not open for further replies.

lresides

Programmer
Aug 9, 2001
7
US
Hi,
There are probably better ways to do this, but now I'm getting frustrated because I can't get csplit to work and it should. (I hate it when things don't work and they should.)

I have a file that looks like this:

Searching DFDSFS
xxxx
xxxx
xxx

Searching SDFDFDS
ZZZZ
ZZZZ

etc

What I would like to do is create one file that contains the Search text for each section...For the above example I'd want 2 files one with :

Searching DFDSFS
xxxx
xxxx
xxx

and the other with :

Searching SDFDFDS
ZZZZ
ZZZZ

I've tried csplit a few different ways.

csplit -k -f cust. custcsmvpl '%Searching%' '{21}'


If the last parm is more than the number of "Searching"s in the file I get

"csplit: 0653-113 {23} is greater than the current line or the end of the file."

If it is less than the number of "Searching"s I get 1 file starting with the data at the nth "Searching".

What am I doing wrong?

Any help would be appreciated, Thanks, Leigh
 
Why not use {*} ? From the man page:

{INTEGER} repeat the previous pattern specified number of times

{*} repeat the previous pattern as many times as possible


 
No luck with the * approach, got the following message:


csplit: 0653-108 {*} is not valid. Specify a numeric repeat count.


Thanks for your time though. Leigh
 
Some non-GNU csplits are pretty unfriendly! I've written a small sh/ksh/bash script that tries to get the number of occurances of the string to feed the '{ }'. In the script, I had to use '/' instead of '%'. This may be what you want anyway. Here is the script. Hope it helps.

#! sh
#
# Usage: cshelper search-string filename
#
ONE=1
OCCURS=`grep $1 $2 | wc -l`
OCCURS=`expr $OCCURS - $ONE`
eval csplit -k $2 '/$1/' '{${OCCURS}}'

ZaSter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top