The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help needed - ksh shell scripting subbu Shell Programming and Scripting 5 02-15-2008 09:53 AM
SHell Scripting Help Needed cskumar Shell Programming and Scripting 2 07-16-2006 10:55 PM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 05:12 AM
help needed in shell scripting......urgent swamymns Shell Programming and Scripting 3 12-06-2005 08:10 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-22-2006
Registered User
 

Join Date: Apr 2006
Posts: 97
Help needed - shell scripting

I have a file that has text in the format below

ABC
/ Some text /
ABC
/ Some text /
ABC
/ Some text /
ABC
/ Some text /
ABC
/ Some text /

How can I seperate the text between a pair of 'ABC' into seperate files ???

any information would be of great help. Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 05-22-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,297
Do you mean you want to create a file that is minus all the ABC's?
Code:
grep -v 'ABC' oldfile > newfile
Reply With Quote
  #3  
Old 05-22-2006
Registered User
 

Join Date: Apr 2006
Posts: 97
no, if we consider the example ... i want to create five different files with the content of each coming from the text betweeen two consecutive 'ABC's
Reply With Quote
  #4  
Old 05-22-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,297
Code:
#/bin/ksh
let filecnt=0
while read record
do
     if [ `echo $record | grep -q '^ABC'` -ne 0 ] ; then
           echo "$record" > newfile"$filecnt"
           let filecnt=$filecnt + 1
     fi
done < oldfile
Reply With Quote
  #5  
Old 05-22-2006
tayyabq8's Avatar
Moderator
 

Join Date: Nov 2004
Location: Bahrain
Posts: 555
If same output can be achieved with sed?

Hi,

Out of interest, is possible to redirect the same output with sed to textfile.$count? using branching (b), hold space or whatsoever is available in sed to output different sections from one file to more than files?

Regards,
Tayyab
Reply With Quote
  #6  
Old 05-22-2006
Registered User
 

Join Date: Apr 2006
Posts: 97
Thsi is gave an error, something regarding ' unary operators for -ne'
Reply With Quote
  #7  
Old 05-22-2006
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
Perhaps use awk...
Code:
$ < infile awk '/ABC/{c++; next} {print > "outfile." c}'

$ head outfile.*
==> outfile.1 <==
/ Some text /

==> outfile.2 <==
/ Some text /

==> outfile.3 <==
/ Some text /

==> outfile.4 <==
/ Some text /

==> outfile.5 <==
/ Some text /
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0