I have a bunch of files whose names start with 'xx'
The first line of each file looks something like:
a|...|...|...|... , ...
In order to rename all of these files to whatever's between the 4th | and the comma (in the first line of that particular file) , I have been using:
But my major problem is that several files have the same string between the 4th | and the comma. When this 'duplication' happens, I want to be able to rename the file to the same thing, but with something appended to the end, like a number or something.
I want to have the same number of files in the end as the number of files I started with, but right now I'm losing many many files since unix is writing overtop of files when the desired name has already been used.
Thank you in advance
Last edited by Yogesh Sawant; 01-19-2010 at 05:17 AM..
Reason: code tags, please
Though your method worked perfectly for a simple test case that I made, it encountered a serious problem for the set of files I am working with.
For one of the files, the string destined to become the filename of that file was "too long" for some reason... and so the entire procedure stopped, and only 84 out of my 1883 files actually got renamed.
This was very strange though because when I was using my original code:
none of the file names were "too long" ... the only problem was that some files were being overwritten due to duplicate naming.
So does anyone know how I could modify my code to avoid the duplicate naming ??
Or a better way of implementing Anbu23's code so as to not have any restriction on the size of a filename ??
I thought that there wasn't any restriction to the size a filename can be in unix.
Hi,
In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this?
I am using #!/bin/ksh
For eg: sftp user@host <<EOF
cd /path
get *.txt
rename *.txt *.txt.done
... (7 Replies)
Hello
I have a folder with around a 100 files. Some of these files have an extension of .DAT.csv and the others are simply .DAT
I need to rename all those files ending in .DAT.csv to .DAT. I tried out the following script:
cd /data/AED/DEV/IN/MENSUEL/B3C/FEERIE/BASCULE/TEST
cnt=1
for fname... (3 Replies)
:wall:
Hello there,
basically in my program where im stuck at is when it comes to rename the files in a loop.
- the program counts the number of files w a given name (works!)
- and then if the number of files is greater or equal to the MAX_VERSIONS (numbers of files allowed w the... (1 Reply)
Hi,
Very silly question. I need to rename all my files located in one particular folder. The names are Results1.dis, Results2.dis, Results3.dis, etc. I need to change the names to Results001.dis, Results002.dis, Results003 so on and so forth. Now, Files with double digits such as Results17.dis... (3 Replies)
Hi All
I have a folder that contains hundreds of file with a names
3.msa
4.msa
21.msa
6.msa
345.msa
456.msa
98.msa
...
...
...
I need rename each of this file by adding "core_" in the begiining of each file such as
core_3.msa
core_4.msa
core_21.msa (4 Replies)
hi ,
I have certain files at the same path with differeent extensions like .dat , .txt etc ...........i need to rename them with extension .found at the same path with the help of loop....
also the files names will be like this ;
abc_2010_c1.dat
abc_2010_c2.dat
xyz_2010_c1.txt (2 Replies)
I have a file that looks like this
2 4 10 500 tim9
5 8 14 700 tim9
3 5 15 432 john1
1 4 12 999 ellen2
So basically what i want to do is fine duplicate names on column 5 and rename it with an extention (i.e. tim9_1 and tim9_2).
so the output file will look like this
2 4 10 500 tim9_1... (1 Reply)
Hi Alll,
I have a script that we use on the servers to change the name of files that have spaces in the name:
#!/bin/tcsh
set n = 0
foreach f ( * )
echo $f | grep " "
if ( $? == 0 ) then
mv "$f" `echo $f | sed -e "s/ /_/g"`
@ n += 1
endif
end
echo $n changed
I need to write a... (2 Replies)
Hello!
I am not familiar with UNIX and I have this problem:
I need to move files from a UNIX machine to a PC. UNIX file names contain ":" as special character which is not recognized in a PC.
How can I change ":" for "_" in the name of a bunch of files in UNIX?
Thanks for your help. (7 Replies)