![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| read list of filenames from text file and remove these files in multiple directories | fxvisions | Shell Programming and Scripting | 5 | 4 Weeks Ago 12:59 PM |
| removing the extension from all filenames in a folder | johnmcclintock | UNIX for Dummies Questions & Answers | 5 | 05-21-2008 05:23 AM |
| Searching filenames containing certain text??? | skyineyes | UNIX for Advanced & Expert Users | 6 | 01-16-2008 03:48 AM |
| Renaming of multiple filenames | shashi_kiran_v | UNIX for Dummies Questions & Answers | 4 | 07-11-2005 04:57 AM |
| Renaming of multiple filenames | shashi_kiran_v | UNIX for Dummies Questions & Answers | 7 | 07-05-2005 05:33 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Removing certain text from multiple filenames
Hi,
I want to remove a ".ff" from multiple filenames. Searching google and these forums brought me close, but no cigar. I know I can use sed to replace what I want, but I'm unsure how to input the filename (filename, not the stuff in the actual file) to the command. For example, I know how to do something simple like: echo filename.ff.txt | sed s/.ff// which displays what i want. How though would I actually do this? Thank you very much, Dan |
| Forum Sponsor | ||
|
|
|
|||
|
I'm a beginner in UNIX. So I can do this in 6 steps.
1) ls -l | awk '{print $9}' > getfilenames1.txt 2) cp filenames1.txt filenames2.txt 3) vi filenames2.txt i) :%s/ff.//g 4) vi filenames1.txt i) :%s/^/mv /g # note blant after mv 5) paste -d" " filenames1.txt filenames2.txt > filename3 6) run filename3. I know it can be done in one command at the prompt. But as a beginner, I have to try. |
|
||||
|
Quote:
|
|
||||
|
Quote:
What would break is if the list of files was in a varible, and this also avouid the fork and exec needed for the other option, additionally you don't need -1 when piping the output of ls as it will output that way anyway when writing to a pipe. If you are using bash or ksh93 you could do this: Code:
for file in *.ff.* ; do
mv "$file" "${file/.ff/}"
done
|
|
|||
|
Thank you very much for the informative replies guys. I used the last one to do the job, as it was quick. I will definitely study sed and awk more though; they seem incredibly useful.
@Smiling Dragon: I take great pains to make sure I never have any spaces in my filenames |