The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk help with string spliting RobertSubnet Shell Programming and Scripting 2 03-12-2009 02:11 PM
awk spliting using separator PrasannaKS Shell Programming and Scripting 1 12-01-2008 04:23 AM
spliting 4gb files to 4*1 gb each jambesh Shell Programming and Scripting 3 07-06-2008 02:50 PM
Help on Spliting files - urgent rajee Shell Programming and Scripting 8 03-10-2008 01:01 PM
spliting up sentences stevox UNIX for Dummies Questions & Answers 2 04-17-2001 04:36 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 4 Weeks Ago
infyanurag infyanurag is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 65
Spliting of two files

hi

I have a log file which contains some reports. The log file looks like this:-

STARTOFREPORT
/tmp
file1.txt
some
text
to
be
folowd
ENDOFREPORT
some non utilized
characters
STARTOFREPORT
/log
file2.txt
more
text
to
be
folowd
ENDOFREPORT
blabla
blak
acd


I want the text between STARTOFREPORT and ENDOFREPORT to be splited in two files i.e. file1.txt and file2.txt and stored at /tmp and /log location respectively.

Please help as how to achieve this

Thanks
  #2 (permalink)  
Old 4 Weeks Ago
scottn scottn is online now Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,115
I suppose one simple approach using awk:


Code:
awk '
  /STARTOFREPORT/ { getline PATH; getline FILE; p = 1; next }
  /ENDOFREPORT/ { p = 0 }
  p { print > PATH "/" FILE }
' input_file

> cat /tmp/file1.txt
some
text
to
be
folowd

> cat /log/file2.txt
more
text
to
be
folowd

  #3 (permalink)  
Old 4 Weeks Ago
infyanurag infyanurag is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 65
Thanks fro your reply.
It works perfect.
just a little confusion.
if the report contains
STARTOFREPORT
/path
file.txt
ENDOFREPORT

no file is created at the location.
Is there any way to create the file at the path, be it of 0bytes.

Thanks
  #4 (permalink)  
Old 4 Weeks Ago
scottn scottn is online now Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,115

Code:
/STARTOFREPORT/ { getline PATH; getline FILE; printf "" > PATH "/" FILE; p = 1; next }

Reply

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 12:26 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