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
joining multiple files into one while putting the filename in the file phil_heath Shell Programming and Scripting 4 2 Weeks Ago 01:15 AM
rename multiple filename.45267.txt to >> filename.txt jason7 Shell Programming and Scripting 6 01-29-2009 05:37 PM
Replace all files with a certain filename with another file Schmellsera UNIX for Dummies Questions & Answers 2 06-30-2008 04:39 PM
gzcat into awk and then change FILENAME and process new FILENAME timj123 Shell Programming and Scripting 6 06-23-2008 07:45 AM
Moving files by splitting the path embedded in the filename rahulrathod UNIX for Dummies Questions & Answers 7 04-14-2005 02:43 AM

Reply
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 1 Week Ago
natalie23 natalie23 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 15
Filename from splitting files to have the same filename of the original file with counter value

Hi all,
I have a list of xml file. I need to split the files to a different files when see the <ko> tag.

The list of filename are
B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml
B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml
B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml

I have a question on how to have the same filename with the counter number append at the end on the filename?

This is the code that I used


perl -n -e '/^<ko>/ and open FH, ">output".$n++; print FH;'

and the filename I get just
output0
output1
output2
output3
output4

Actually,the filename that I needed:

B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml_output0
B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml_output1
B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml_output2
B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml_output3
B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml_output4

B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml_output0
B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml_output1
B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml_output2
B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml_output3
B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml_output4

B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml_output0
B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml_output1
B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml_output2
B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml_output3
B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml_output4

How do modify this code "perl -n -e '/^<ko>/ and open FH, ">output".$n++; print FH;' " so that I can have the filename that I want?
Anyone have any idea?

Thanks in advance!

Last edited by natalie23; 1 Week Ago at 02:29 AM..
  #2 (permalink)  
Old 1 Week Ago
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,078
Code:
while(<DATA>){
	chomp;
	for (my $i=0;$i<=5;$i++){
		print $_,"_output",$i,"\n";
	}
	print "\n";
}
__DATA__
B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml
B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml
B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml
  #3 (permalink)  
Old 1 Week Ago
natalie23 natalie23 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 15
Hi summer cherry,

Thanks for your help.

However, from your code, where should I put my code?

Thanks!
  #4 (permalink)  
Old 1 Week Ago
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,291
With awk:

Code:
awk -F"[-.]" '{for(i=0;i<5;i++)print $0 "_output" i}' file
Sponsored Links
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 03:23 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