[Solved] Appending beginning of filename to end


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] Appending beginning of filename to end
# 1  
Old 01-22-2014
[Solved] Appending beginning of filename to end

Hi Guys,

I have serveral directories like this:

Code:
(2013) blablabla(blabla) - blabla (blabla)

or
Code:
(1997) blablabla(blabla) - blabla (blabla)

and have to rename them to something like that:

Code:
blablabla(blabla) - blabla (blabla) (2013)

and
Code:
blablabla(blabla) - blabla (blabla) (1997)

Easy task, but I'm new to this and couldn't come up with a solution.

Thanks in advance!

Last edited by Nateshift; 01-22-2014 at 11:50 AM..
# 2  
Old 01-22-2014
Code:
for dir in *bla*
do
        if [ -d "$dir" ]
        then
                sfx="${dir%% *}"
                mv "$dir" "${dir#* } $sfx"
        fi
done

These 2 Users Gave Thanks to Yoda For This Post:
# 3  
Old 01-22-2014
Works like a charm!

Thanks!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Add part of pathname/subfolder name to beginning of filename

Hello everyone, I need some help renaming files. I have a directory with a bunch of subfolders in it like so with DWI being the working directory and the 3 levels after it being subdirectories home/user/Documents/DWI/111180-100/3t_2016-01-07_21-42/003_DTI_siemens_TClessdistort/dtifit_FA.nii.gz... (8 Replies)
Discussion started by: azurite
8 Replies

2. Shell Programming and Scripting

How to append in the beginning not at the end?

Hi, I now that >> will append text to the end of the text that is already inside the file. How to append the new text infront of the text that is already in the file. Thanks for any input. Regards, Chandu (3 Replies)
Discussion started by: chandrakanth
3 Replies

3. Shell Programming and Scripting

Add new line at beginning and end of a file

Hi, I have a specific requirement to add text at the beginning and end of a plain text file. I tried to use "sed" with '1i' and '$a' flags but these required two separate "sed" commands separated with "|". I am looking for some command/option to join these two in single command parameter. ... (6 Replies)
Discussion started by: bhupinder08
6 Replies

4. Shell Programming and Scripting

Removing hyphen from beginning and end of a word only.

It is very simple to remove a hyphen from a word anywhere in that word using a simple sed command (sed -i 's/-//g' filename), but I am not able to figure out how to do this: For example, apple -orange tree pipe- banana-shake dupe- What my output should look like: apple orange tree... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

5. Shell Programming and Scripting

trying to add text to beginning and end of each line

Well here goes: I tried to write a batch file that adds a specific fixed text to each line of an already existing text file. for the adding text infront of each line I tried this: for /F "delims=" %%j in (list.txt) do echo.STARTTEXT\%%j >> list.txt for adding text after each line I... (0 Replies)
Discussion started by: pasc
0 Replies

6. Shell Programming and Scripting

script to include filename with variations at the beginning of the file

Hi there, I have a bunch of files that I want to modify. As a beginner, but nevertheless enthusiast, in the use of the shell I want to create a script enabling me to modify those files quickly. I had only some partial success with various peaces of scripts but I would like to create one script... (1 Reply)
Discussion started by: iamzesh
1 Replies

7. Shell Programming and Scripting

Remove comma and next rows beginning from the end

Hello friends, I have a file which consists of many rows, I use a couple of commands to convert it so i can use in a database query for filtering. I need the first columns (msisdns) in a row, seperated with commas, 9855162267,4,5,2010-11-03 17:02:07.627 9594567938f,5,5,2010-11-02... (9 Replies)
Discussion started by: EAGL€
9 Replies

8. UNIX for Dummies Questions & Answers

Appending at the beginning of the file.

Hi, I am using ">>" to append to the existing file but I appens to the end of the file but I want to add tne new things at the beginning. Do we have any functionality to do that? Thanks, Siba (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

9. UNIX for Dummies Questions & Answers

cat a file from end to beginning

Is there an option, for cat, head, tail, or is there any way, to display a file from last line to first? For example, my file looks like this: aaaa bbbb cccc eeee and I would like to print or display it like this: eeee cccc bbbb aaaa thanks (5 Replies)
Discussion started by: jpprial
5 Replies
Login or Register to Ask a Question