joining variable to the end of a file name


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers joining variable to the end of a file name
# 1  
Old 08-04-2008
joining variable to the end of a file name

hi all
i have a directory which contain file
20060101-66666-09-08-0.tif
20060101-77777-11-12-0.tif
20051231-54221-66-55.tif
20051231-54221-66-44.tif
as you can see the name of the two last files is shorter then the first ones
i want to take all the files with the shorter name and to add to their name
-0 before the .tif (format as the two forst files)
how shall i do it?
thanks in advance
note:this are just example to the name of the files
i have something like 600 files.
# 2  
Old 08-04-2008
Something like this maybe?

Code:
sed -n 's/\(.*-[0-9][0-9]\)\(\.tif\)/echo mv "\1\2" "\1-0\2"/p' file | sh

If it looks like it does what you want it to do, take out the "echo" and run it again.
# 3  
Old 08-04-2008
hi
thanks for quick response
i did like you've wrote
here are the result
sed: -e expression #1, char 57: Unmatched ) or \)
it's an error
can you please tell me what is wrong
and please a little explanation about the command.
thanks
# 4  
Old 08-04-2008
I made a mistake but I edited the posting quickly; sorry if you got the wrong version.

There are multiple dialects of sed out there, so it's also possible that your sed simply isn't compatible with mine.

This prints file names which have two digits before the .tif extension and adds a -0 before the extension.
# 5  
Old 08-04-2008
hi era
i'm sorry it was my mistake i did it from a directory which i don't have a grant
to.
however now i did it from other directory
and this is what it worte
sed: can't read file: No such file or directory
can someone tell what is the problem ?
thanks you
# 6  
Old 08-04-2008
It expects the list of file names in a file called file. Sorry for not making that clear.

Try this instead:

Code:
ls | sed -n 's/\(.*-[0-9][0-9]\)\(\.tif\)/echo mv "\1\2" "\1-0\2"/p' | sh

# 7  
Old 08-04-2008
thank you very much .
it works great
Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

File joining and sorting

Hi, I'm having some trouble joining these two files for some reason. Here is what they look like: head * I'm using: join -a 1 -1 2 -2 1 f1 f2 -t, > joinfile.out but unfortunately nothing is happening. I did notice that I was having trouble sorting f1 and I'm not sure why using:... (6 Replies)
Discussion started by: verse123
6 Replies

2. Shell Programming and Scripting

Joining lines in a file - help!

I'm looking for a way to join lines in a file; e.,g consider the following R|This is line 1 R|This is line 2 R|This is line 3 R|This is line 4 R|This is line 5 what i want to end up with is R|This is line 1 R|This is line 2 R|This is line 3 R|This is line 4 R|This is line 5 so... (15 Replies)
Discussion started by: Storms
15 Replies

3. Shell Programming and Scripting

bash - joining lines in a file

I’m writing a bash shell script and I want to join lines together where two variables on each line are the same ie. 12345variablestuff43212morevariablestuff 12345variablestuff43212morevariablestuff 34657variablestuff78945morevariablestuff 34657variablestuff78945morevariablestuff... (12 Replies)
Discussion started by: Cultcha
12 Replies

4. Shell Programming and Scripting

Appending string, variable to file at the start and string at end

Hi , I have below file with 13 columns. I need 2-13 columns seperated by comma and I want to append each row with a string "INSERT INTO xxx" in the begining as 1st column and then a variable "$node" and then $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13 and at the end another string " ; COMMIT;" ... (4 Replies)
Discussion started by: Vaddadi
4 Replies

5. Shell Programming and Scripting

variable joining

I really need help on this problem. The story: My VAR1 and VAR2 works fine and able to get the value. I want to do as "if VAR1 or VAR2 is bigger than max_loadavg then the code will run...then if VAR1 or VAR2 is lesser than min_loadavg then the other code will run... The problem: The... (8 Replies)
Discussion started by: hezry79
8 Replies

6. Shell Programming and Scripting

Add end of char \n on end of file

Hi, I want to add \n as a EOF at the end of file if it does't exist in a single command. How to do this? when I use command echo "1\n" > a.txt and od -c a.txt 0000000 1 \n \n 0000003 How does it differentiate \n and eof in this case? Regards, Venkat (1 Reply)
Discussion started by: svenkatareddy
1 Replies

7. Shell Programming and Scripting

Joining two arrays and then creating a variable

Hello all... I'd like to create a variable from an array element from two arrays. In my search for answers I found this code for bash that joins two arrays and then started to work with it. I had got to work once and then foolishly without saving the code, I started to edit it for ksh and... (4 Replies)
Discussion started by: carlos25
4 Replies

8. Shell Programming and Scripting

Joining program to one batch file

I created a batch file (./mybatch) that need to run few programs at a sequnece but i need a command like the DOS call command in order to return to the main batch file to proceed the sequence example: cd /dir1/path/dir2 invoke program1 cd /dir3/path2/ <--- i want to return here (2 Replies)
Discussion started by: eynkesef
2 Replies

9. Shell Programming and Scripting

Joining 2 lines in a file together

Hi guys, I've got a log file which has entries that look like this: ------------------------------------------------------------------------------- 06/08/04 07:57:57 AMQ9002: Channel program started. EXPLANATION: Channel program 'INSCCPQ1.HSMTSPQ1' started. ACTION: None. ... (3 Replies)
Discussion started by: m223464
3 Replies

10. Shell Programming and Scripting

Joining lines in log file

Hi, I need to develop a script to join multiple three lines in a log file into one line for processing with awk and grep. I looked at tr with no success. The first line contains the date time information. The second line contains the error line. The third line is a blank line. Thanks, Mike (3 Replies)
Discussion started by: bubba112557
3 Replies
Login or Register to Ask a Question