![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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.. |
|
||||
|
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
|
|
||||
|
With awk:
Code:
awk -F"[-.]" '{for(i=0;i<5;i++)print $0 "_output" i}' file
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|