split files by specifying a string (bash shell)
Hi all,
I have a file of around 300 lines in which string "SERVER" occurs around 32 times. for eg. Quote:
Quote:
awk '/SERVER/{n++}{print > f n}' f=/vikas/list /vikas/final But the problem is that it makes maximum of 10 files, but I need more than 30. I have tried using nawk, but didnt worked. I am using bash scripting on Sun OS. Any other way of splitting this data ??? Pls help !!! Thanks in adv. Regards, Vikas |
Yeah, there is a limit in solaris awk for the number of simultaneously opened files, but using nawk you can close the file terminating the streaming output. In this way you can write an unlimited number of files. I am thinking about something like this:
Code:
nawk '/SERVER/{close(oufile) ; n++ ; oufile=sprintf("%s%02s",f,n)}{ print > oufile }' f=/vikas/list /vikas/final |
Code:
awk ' |
ghostdog74, maybe I am missing something, but what is the improvement of your replay in respect of mine? "Use indentation"?! "Don't use external variables"?! ...
|
Quote:
|
Hmmm... it looks like you've looked for details after my last post and not really cared about the previous solution. The same for editing your code, by removing an unuseful part. The call to sprintf in my contribution just makes the filenames of the same length. Anyway, I am not questioning about the code, the solution, nor about your ability in awk programming. I saw other posts from you and you're really good. No kiddin'. What makes me angry sometimes, is the fact that a lot of people reply to the OP without caring about replies from other members. This is a little unfair since every little contribution is worth to be read before evaluating that something more can be told: comments, add-ons, notes, disapprovals... whatever! Maybe, just my personal opinion.
|
wow you are so sensitive and so serious...relax....i sometimes feel the same way, but so what?! life goes on. an example, sometimes, you know someone posted a homework/assignment, and you refrain from answering, but so what ??, someone will just come in and provide an answer...should i get angry every time such things happen? i just move on.. there are more important things to do in life than be concerned about minor things such as this.
|
Hi.
Quote:
I don't agree that every reply is a worthwhile contribution, because they can be inane, erroneous, malicious, off-topic, etc. As ghostdog74 says -- just move on, or do some yoga, get a drink of water, whatever helps you relax ... cheers, makyo |
Got the point! You both are right! I think I get something to drink and relax now... cheers! :)
|
Hi.
Command csplit was invented to solve these kinds of problems generally: Code:
#!/usr/bin/env sh Code:
% ./s2 |
Hi All
Hi,
I tried lots of commands including the above ones. They all run fine on Linux machines BUT not on the solaris machines, dont know the reason behind it. Anyways, MANY MANY THANKS to all for your time and help. I found this command to work perfectly. Code:
/usr/xpg4/bin/awk '/SERVER/{n++}{print > f n}' f=/vikas/list /vikas/final |
Quote:
|
Quote:
|
All times are GMT -5. The time now is 07:31 AM. |