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
command for selecting specific lines from a script gardasgangadhar UNIX for Dummies Questions & Answers 1 05-13-2008 02:29 AM
shell script to search content of file with timestamps in the directory psychobeauty Shell Programming and Scripting 10 04-21-2008 02:37 AM
Retreive content between specific lines ina file chennaitomcruis Shell Programming and Scripting 4 04-19-2008 07:18 AM
Help with selecting specific lines in a large file tansha UNIX for Dummies Questions & Answers 2 02-06-2008 04:26 AM
shell script to edit the content of a file tiger99 Shell Programming and Scripting 3 01-31-2008 12:43 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-08-2008
Registered User
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 128
Stumble this Post!
Urgent: selecting unique specific content of a file using shell script

Hi,

I have a file whose content and format at places is as given below.

print
coloumn ....
coloumn ....
coloumn ....
skip 1 line

print
coloumn ...
skip 1 line


I need to select the following :
print
coloumn ....
coloumn ....
coloumn ....
skip 1 line

and write it into a new file.
And the next
print
coloumn ...
skip 1 line
should be again written to another new file.Both by using shell script.

Thanks in advance
JS
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-08-2008
dj -------
 

Join Date: Feb 2007
Location: Cochin/Bangalore, India
Posts: 380
Stumble this Post!
Code:
num=1
while read line
        do
        [[ "$line" != "END" ]] && { echo "$line">>file_number.$num; }|| { echo "END">>file_number.$num; (( num = num + 1 )); }
        done<file
Reply With Quote
  #3 (permalink)  
Old 01-08-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,521
Stumble this Post!
With Awk:

Code:
awk '{close(FILENAME"_"f-1);print>(FILENAME"_"($1=="print"?++f:f))}' data
Use nawk or /usr/xpg4/bin/awk on Solaris.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:08 PM.


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

Content Relevant URLs by vBSEO 3.2.0