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
Splitting file based on number of rows wahi80 Shell Programming and Scripting 2 06-03-2008 09:38 PM
Spliting file based on condition Raamc Shell Programming and Scripting 2 05-15-2008 11:51 AM
Splitting av file in 2 at specific place based on textpattern borgeh Shell Programming and Scripting 0 09-24-2007 07:02 PM
Read file based on condition sbasetty Shell Programming and Scripting 5 02-01-2007 02:54 AM
splitting files based on text in the file matrix1067 Shell Programming and Scripting 1 01-30-2006 08:45 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 12-07-2005
srivsn srivsn is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 32
Unhappy Splitting a file based on some condition and naming them

I have a file given below. I want to split the file where ever I came across
***(instead you can put ### symbols in the file) . Also I need to name the file by extracting the report name from the first line which is in bold(eg:RPT507A) concatinated with DD(day on which the file runs). Can someone help me out in this......................

Thanks in advance
srivsn





==================================================================================================== ================================
RPT507A BBW \CDL01 prd1 STORED VALUE SYSTEMS Page 1
Bath and Body Works Disputed Transactions Report Job: 65
Wed 01:55:12 Settlement file dated 10/25/2005 Oct 26 2005
==================================================================================================== ================================
STORE CARD NUMBER DATE TIME AMOUNT MERCHANT INVOICE NO SEQ# CODE Reason
__________ ___________________ __________ ________ __________________ ________ __________ ______ ____ ___________________

==================================================================================================== ================================
RPT507A BBW \CDL01 prd1 STORED VALUE SYSTEMS Page 2
Bath and Body Works Disputed Transactions Report Job: 65
Wed 01:55:13 Settlement file dated 10/25/2005 Oct 26 2005
==================================================================================================== ================================
STORE CARD NUMBER DATE TIME AMOUNT MERCHANT INVOICE NO SEQ# CODE Reason
__________ ___________________ __________ ________ __________________ ________ __________ ______ ____ ___________________

==================================================================================================== ================================
RPT507A BBW \CDL01 prd1 STORED VALUE SYSTEMS Page 3
Bath and Body Works Disputed Transactions Report Job: 65
Wed 01:55:13 Settlement file dated 10/25/2005 Oct 26 2005
==================================================================================================== ================================
STORE CARD NUMBER DATE TIME AMOUNT MERCHANT INVOICE NO SEQ# CODE Reason
__________ ___________________ __________ ________ __________________ ________ __________ ______ ____ ___________________

==================================================================================================== ================================
RPT507A BBW \CDL01 prd1 STORED VALUE SYSTEMS Page 4
Bath and Body Works Disputed Transactions Report Job: 65
Wed 01:55:14 Settlement file dated 10/25/2005 Oct 26 2005
==================================================================================================== ================================
STORE CARD NUMBER DATE TIME AMOUNT MERCHANT INVOICE NO SEQ# CODE Reason
__________ ___________________ __________ ________ __________________ ________ __________ ______ ____ ___________________

==================================================================================================== ================================
RPT507A BBW \CDL01 prd1 STORED VALUE SYSTEMS Page 5
Bath and Body Works Disputed Transactions Report Job: 65
Wed 01:55:15 Settlement file dated 10/25/2005 Oct 26 2005
==================================================================================================== ================================
STORE CARD NUMBER DATE TIME AMOUNT MERCHANT INVOICE NO SEQ# CODE Reason
__________ ___________________ __________ ________ __________________ ________ __________ ______ ____ ___________________


==================================================================================================== ================================
RPT507A BBW \CDL01 prd1 STORED VALUE SYSTEMS Page 6
Bath and Body Works Disputed Transactions Report Job: 65
Wed 01:55:16 Settlement file dated 10/25/2005 Oct 26 2005
==================================================================================================== ================================
STORE CARD NUMBER DATE TIME AMOUNT MERCHANT INVOICE NO SEQ# CODE Reason
__________ ___________________ __________ ________ __________________ ________ __________ ______ ____ ___________________


==================================================================================================== ================================
RPT507A BBW \CDL01 prd1 STORED VALUE SYSTEMS Page 7
Bath and Body Works Disputed Transactions Report Job: 65
Wed 01:55:16 Settlement file dated 10/25/2005 Oct 26 2005
==================================================================================================== ================================
STORE CARD NUMBER DATE TIME AMOUNT MERCHANT INVOICE NO SEQ# CODE Reason
__________ ___________________ __________ ________ __________________ ________ __________ ______ ____ ___________________



* * * END OF REPORT * * *
### Job 65 (RPT507A BBW ): 390 lines, 7 pages, 10/26/2005 01:55:16
==================================================================================================== ================================
RPT507B BBW \CDL01 prd1 STORED VALUE SYSTEMS Page 1
Bath and Body Works Disputed Transactions Report Job: 86
Wed 01:55:17 Settlement file dated 10/25/2005 Oct 26 2005
==================================================================================================== ================================



* * * END OF REPORT * * *
### Job 86 (RPT507B BBW ): 25 lines, 1 pages, 10/26/2005 01:55:17
==================================================================================================== ================================
RPT507B BBWCC \CDL01 prd1 STORED VALUE SYSTEMS Page 1
White Barn Candle Company Disputed Transactions Report Job: 87
Wed 01:55:17 Settlement file dated 10/25/2005 Oct 26 2005
==================================================================================================== ================================



* * * END OF REPORT * * *
  #2 (permalink)  
Old 12-07-2005
grasper grasper is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 45
I'd use perl for something that involved.Something like:-

#!/usr/bin/perl

# Use Perls localtime function if you want, but this is plainer
$date=`date '+%d_%m'`;
chomp($date);

open (INPUTFILE, "<./report_file.rep");
(@file)=<INPUTFILE>;
close INPUTFILE;

@report_names=grep (/RPT/,@file);
@reports=split(/\*\*\*.*?\*\*\*/, join("",@file));


$count=0;
foreach $report_name(@report_names) {
$report_name=~s/(\w+)\W.*/\1/;
chomp($report_name);
$filename="${report_name}_${date}";

open (FILE, ">./$filename");
print FILE "$reports[$count]\n";
close FILE;

$count++;
}


You'll probably need to tweak the 'split' function a bit so each file contains exactly what you want, but that (roughly) should do it.
Sponsored Links
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 03:42 AM.


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