You are not logged in.

#1 2010-07-24 06:13:38

arch0r
Member
From: From the Chron-o-John
Registered: 2008-05-13
Posts: 597

remove certain part of file name

hey all :>
i have several files which start with an URL in the file name such as www.foo.net_01.foo.jpg.
how can i remove the url in the beginning that i have a clean filename (foo.jpg)?

after some googling i found out that it's possible with find and sed but i have no clue how to exactly strip the file name with sed hmm

thanks in advance and best regards :>

Offline

#2 2010-07-24 06:33:35

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 881
Website

Re: remove certain part of file name

prename 's/^www\..+_(.+)$/$1/g' *.jpg

It'll croak on www.foo.com_file_name.jpg (you should provide real input and expected output)

Offline

#3 2010-07-26 09:53:42

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: remove certain part of file name

#!/bin/bash
for file in *
do
     newname1=${file##*_}
     newname2=${newname1#*.}
#  echo $file - $newname2
     mv $file $newname2
done

Untested, so recommend running with mv line commented and echo line uncommented first.

If you have files in the dir that do not fit the name format, you may want to put in an if statement to ignore those - I use =~ and a regular expression.

Keeping it around as a script is probably a good idea.

Last edited by skanky (2010-07-26 10:00:33)


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#4 2010-07-26 10:04:38

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,356

Re: remove certain part of file name

For a graphical method try using gprename, its in the repos.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#5 2010-07-26 10:10:09

splittercode
Member
From: WI, USA
Registered: 2010-03-16
Posts: 203

Re: remove certain part of file name

rename www.foo.net_01. '' www.foo.net_01.*

works as well.

(obviously only if they all start with the same url)

Last edited by splittercode (2010-07-26 10:12:52)

Offline

Board footer

Powered by FluxBB