The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 12:53 PM
SHell Scripting Help Needed cskumar Shell Programming and Scripting 2 07-17-2006 01:55 AM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 08:12 AM
help needed in shell scripting......urgent swamymns Shell Programming and Scripting 3 12-06-2005 11:10 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-22-2006
garric garric is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 99
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
  #2 (permalink)  
Old 05-22-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Do you mean you want to create a file that is minus all the ABC's?
Code:
grep -v 'ABC' oldfile > newfile
  #3 (permalink)  
Old 05-22-2006
garric garric is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 99
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
  #4 (permalink)  
Old 05-22-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
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
  #5 (permalink)  
Old 05-22-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
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
  #6 (permalink)  
Old 05-22-2006
garric garric is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 99
Thsi is gave an error, something regarding ' unary operators for -ne'
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0