remove filename prefix


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers remove filename prefix
# 1  
Old 07-10-2002
remove filename prefix

I've got a bunch of files called oldabc, olddef etc.

i want to copy these to be abc, def....

I can do this with file extensions....but can get the logic to work for prefixes. All the files I am interested in have a prefix of 'old'.

This loop is no good for me....it looks at the content of the files...rather than changing the filename.

for files in `ls *fmt`;
do
newfilename="cut -c4-50 $files";
cp $files $newfilename;
done

How do I get it to look at the filename and change it - rather than the content of the file?
# 2  
Old 07-11-2002
>for files in `ls *fmt`;
>do
newfilename="cut -c4-50 $files>";
>cp $files $newfilename;
>done

Code:
for files in `ls *fmt`
do
newfilename=`echo $files | cut -c4-`
cp $files $newfilename
done


Last edited by hell666; 07-11-2002 at 10:15 AM..
# 3  
Old 07-11-2002
ahhhh - echo...of course...great thanks.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract Uniq prefix from a start and end prefix

Dear All, assume i have a file with content: <Start>6000</Start> <Stop>7599</Stop> the output is: 6000 7000 7100 7200 7300 7400 7599 how should we use any awk, sed, perl can do this task, means to extract the uniq prefixes from the start and stop prefix. Thanks Jimmy (3 Replies)
Discussion started by: jimmy_y
3 Replies

2. Shell Programming and Scripting

Using filename to determine a prefix that needs to be added to string column on file?

Possible filenames: CDD_Whatever.txt DDD_Whatever.txt If the file prefix = CDD, I'd like to prefix every person ID (second column in my examples below) on the file with "c-" If the file prefix = DDD, I'd like to prefix ever person ID with "d-" Input: Desired Output: Any help... (2 Replies)
Discussion started by: lrluis
2 Replies

3. Shell Programming and Scripting

remove the filename from a string

I have a string like this /Development/ST/st000001su/Outbound/Prod/PROD-732QCJ/63acf2caf91bc136cb9bcce8a85c7fa8/PGP/PGP.txt I want to remove the PGP.txt and I want only the /Development/ST/st000001su/Outbound/Prod/MCFR-732QCJ/63acf2caf91bc136cb9bcce8a85c7fa8/PGP returned. I saw an command... (2 Replies)
Discussion started by: srini0603
2 Replies

4. Shell Programming and Scripting

How to remove filename from the path

Hi, I have a list of paths with files at the end. How can strip off filenames. This is what I have: /apps/test/abc/file.txt /apps/new/home/daily/report.xml /apps/old/home/weekly/out/test.sh This is what I need: /apps/test/abc/ /apps/new/home/daily/ /apps/old/home/weekly/out/ ... (10 Replies)
Discussion started by: djanu
10 Replies

5. Shell Programming and Scripting

Remove prefix per line in file

Hi, I'm using a .ksh script to split one file into multible files by checking for the prefix per line. It works perfekt (thanks again for anyone involved in helping me with that ;)), but I want to remove the prefix per line too. Means only the line information itself should remain in the... (7 Replies)
Discussion started by: spidermike
7 Replies

6. Shell Programming and Scripting

how to remove last two extensions of a filename

hi how to remove extensions of a file.. suppose i have a filename "gtk2-2.4.13-24.el4.x86_64.rpm" and i want the file name as "gtk2-2.4.13-24.el4" means want to remove last two "." extensions of a file can anyone help me in this thanks in advance srik (12 Replies)
Discussion started by: srikanthg
12 Replies

7. Shell Programming and Scripting

Remove prefix using awk

Remove prefix using awk File: nawk -F"|" '{if ($1 ~ /^xyz./) print; else { gsub(.*\..*, \..*, $1) ;print }}' file Error: ouput required: (5 Replies)
Discussion started by: pinnacle
5 Replies

8. UNIX for Dummies Questions & Answers

Remove path from filename

In a foreach loop I end up with $file containing the filename INCLUDING the whole path. I want this reduced to just the filename, but I can't seem to remember how I did it some years back. I am sure I can do it with "sed", but I am pretty sure I have seen a simpler command. Anyone? borgeh (3 Replies)
Discussion started by: borgeh
3 Replies

9. UNIX for Dummies Questions & Answers

Use same filename for prefix in the split command

I want to execute something like this: find . -type f -regex '$REGEX' -print | xargs split -d -C $SIZE The problem is that I want the name of the split files to be the same name as original files. So if my directory has two files called abc.txt and def.txt, then I want the split files to be... (1 Reply)
Discussion started by: namityadav
1 Replies

10. Shell Programming and Scripting

Remove prefix from filenames

I'm trying to put together a shell script that will append specific prefixes based on the content of filenames. I think I have this part down. However, I want to append before that part a process that will remove the current prefix before it renames the files with the new prefix. For example,... (6 Replies)
Discussion started by: HLee1981
6 Replies
Login or Register to Ask a Question