renaming the default output name of the split command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting renaming the default output name of the split command
# 1  
Old 11-13-2011
renaming the default output name of the split command

Hello,

I would like to split a file but I dont what the subfiles to be named the way they are:

Code:
 
ex:
default name: xaa xab xac xad xae
desired name: b01 b02 b03 b04 b05

I know I can rename them afterwards however I have a varialbe split lenghth, in other words I am not sure how many subfiles I will have.
That is up to the user of the script.

I am using an if statement for renaming these but it makes my script really long and I can never catch all the possibilites since there are infinit number of subfiles the user might want.

This is what I am doing (not very smart):
Code:
 
If ( `echo $NumofSub` == 2 ) then
  mv xaa b01.txt
  mv xab b02.txt
else if ( ..... so forth

I hope I am clear enough, but if not please let me know if you have any
questions. I am using tcsh by the way I know I shouldnt but my whole script is in tcsh, cant change it now.

Have learnd my lesson and will most likely use bash for my next script.

---------- Post updated 11-13-11 at 01:02 AM ---------- Previous update was 11-12-11 at 11:52 PM ----------

if any one is interested, I wrote this which works Smilie.

Code:
 
#!/bin/tcsh
#batch rename
 
split -l 40 260_sites.txt
@ bnum = 1
foreach batch ( `ls | grep xa` )
 mv $batch b0"$bnum".txt
 @ bnum = $bnum + 1
end


Last edited by smarones; 11-13-2011 at 01:13 AM..
# 2  
Old 11-13-2011
Using bash.
Code:
ls x[a-z][a-z] | while read file;do let c++;echo mv $file b$(printf "%02d" $c)".txt";done
mv xaa b01.txt
mv xab b02.txt
mv xac b03.txt
mv xad b04.txt
mv xae b05.txt

When you are safe , just remove the echo
# 3  
Old 11-13-2011
Try this:
Code:
~/unix.com$ split -d -a 3 -l 240 file b

-d adds digit prefixes instead of alphabetic
-a 3 allows you to add more digits to output files.
b is the prefix to use
In this example: output will be b000...b999

Last edited by tukuyomi; 11-13-2011 at 06:08 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Split Command Generating Incomplete Output Files

Hello All, May i please know how do i ensure my split command would NOT generate incomplete output files like below, the last lines in each file is missing some columns or last line is complete. split -b 50GB File File_ File_aa |551|70210203|xxxxxxx|12/22/2010 20:44:58|11/01/2010... (1 Reply)
Discussion started by: Ariean
1 Replies

2. Shell Programming and Scripting

Insert title as output of command to appended file if no output from command

I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place. What I need The following command is placed at the prompt: TICLI... (4 Replies)
Discussion started by: jbrass
4 Replies

3. Shell Programming and Scripting

Regex to split a string and write the output in another file.

hi, i am trying to write a script to generate ouput in the following format: ##### buildappi abcd_sh nodebug.##### ##### buildappi ijk_sh nodebug.##### The given string is as follows: xtopSharedDLLs = "abcd_sh def_sh ijk_sh " \ + "jkl_sh any_sh... (15 Replies)
Discussion started by: Rashid Khan
15 Replies

4. Shell Programming and Scripting

Split the file with renaming.

Hi Team,. I am writing a script find the files which is not .gz format, split it into files which are 50000 line entries per file(using split -l 50000) then compress the smaller files using gzip and delete the original/big file. After splitting it is creating the files in its own naming... (4 Replies)
Discussion started by: Satish Shettar
4 Replies

5. Shell Programming and Scripting

How to split the sql output into two different variables

Hi, How to set as variable from sql output. Query: select aa.serial, ao.name from ann_amit aa JOIN ann_object ao on (aa.classid=ao.classid); I got two values from aa.serial and ao.name, I wanna make two different variable for aa.serial and ao.name. The value of aa.serial should be in... (2 Replies)
Discussion started by: KarthikPS
2 Replies

6. Shell Programming and Scripting

Need to split the $PATH output

Hi, /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin i want to print the above output as below /usr/kerberos/sbin /usr/kerberos/bin /usr/local/sbin /usr/local/bin /sbin /bin /usr/sbin /usr/bin... (5 Replies)
Discussion started by: kmvinay
5 Replies

7. Shell Programming and Scripting

Split function input and output order

Dear Forum I'm Trying to use split function to split a string, but the output is not as the same order as of the string, please see simple example echo " " | nawk -v var="First;Second;Third;Fourth" ' BEGIN {split(var, arr,";") for(i in arr){print arr }}' The output is Second Third... (6 Replies)
Discussion started by: yahyaaa
6 Replies

8. Shell Programming and Scripting

renaming files using split with a delimiter

I have a directory of files that I need to rename by splitting the first and second halves of the filenames using the delimiter "-O" and then renaming with the second half first, followed by two underscores and then the first half. For example, natfinal1995annvol1_14.pdf -O filenum-20639 will be... (2 Replies)
Discussion started by: swimulator
2 Replies

9. Shell Programming and Scripting

how to get split output of a file, using perl script

Hi, I have file: data.log.1 ### s1 main.build.3495 main.build.199 main.build.3408 ###s2 main.build.3495 main.build.3408 main.build.199 I want to read this file and store in two arrays in Perl. I have following command, which is working fine on command prompt. perl -n -e... (1 Reply)
Discussion started by: ashvini
1 Replies

10. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies
Login or Register to Ask a Question