Results 1 to 5 of 5
Dear all,
I've a folder with some files inside. Synthax: field.field.field.ext
But I would like to replace the . by _ or space.
We give me this command: sed -e ...
- 11-08-2010 #1Just Joined!
- Join Date
- Aug 2010
- Posts
- 22
Replace char with sed
Dear all,
I've a folder with some files inside. Synthax: field.field.field.ext
But I would like to replace the . by _ or space.
We give me this command: sed -e 's/./_/g'
But I'm not an expert in script. But this will replace the point of my extensions too...
How can I do to replace only the point in the name and not the point of the extension in all files in one times?
Mouglou
- 11-08-2010 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
let "A" be the line "field.field.field.ext"
then
rev A | sed 's/\./#/' | sed 's/\./_/g' | sed 's/#/\./' |rev >B
should leave "B" as "field_field_field.ext"the sun is new every day (heraclitus)
- 11-09-2010 #3Linux User
- Join Date
- Jan 2005
- Location
- Saint Paul, MN
- Posts
- 262
I beleive that you are asking how to rename files within a directory and not names in a file?? If that is the case, then use the script:Dear all,
I've a folder with some files inside. Syntax: field.field.field.ext
But I would like to replace the . by _ or space.
We give me this command: sed -e 's/./_/g'
But I'm not an expert in script. But this will replace the point of my extensions too...
How can I do to replace only the point in the name and not the point of the extension in all files in one times?
Mouglou
Which is run as:Code:#!/bin/bash for fullfilename in "$@"; do ext="${fullfilename##*\.}" name="${fullfilename%\.${ext}}" mv "${fullfilename}" "${name//./_}.${ext}" done
Be sure to chmod the script to 755 before attempting to run the script.Code:cd directorylocation scriptname *
- 11-09-2010 #4Just Joined!
- Join Date
- Aug 2010
- Posts
- 12
I tried and got a similar style to tpl. Its like that ,
sed 's/\./_/g' inputfile | rev | sed 's/\_/\./' | rev > outputfile
Sed is really great.
- 11-10-2010 #5Linux User
- Join Date
- Jan 2005
- Location
- Saint Paul, MN
- Posts
- 262
Doing renaming of files within a directory ....
I like to use a function like this to test a script. As you can see that the "mv" (remame) is just being echoed.Code:bash$ function testing > { > for fullfilename in "$@"; do > ext="${fullfilename##*\.}" > name="${fullfilename%\.${ext}}" > echo mv "${fullfilename}" "${name//./_}.${ext}" > done > } bash$ testing field.field.field.ext name.segment.here.with.an.ext mv field.field.field.ext field_field_field.ext mv name.segment.here.with.an.ext name_segment_here_with_an.ext bash$


Reply With Quote
