Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to rename the files given below and move to some other path

1234551abcde20140718023216001.txt.809047512.2014_07_07_13:47:44
000001abcde20140718023216001.txt.34568.001.2014_07_07_13:50:44
44444abcded20140718023216001.txt.1111111.2014_07_07_13:47:44

expected Result

1234551abcde20140718023216001.txt.809047512
000001abcde20140718023216001.txt.34568.001
44444abcded20140718023216001.txt.1111111

only I need to remove the timestamp attached every time with the filenames,and move it to other directory in AIX please help me to write the script.I am new to Unix as I am able to rename single single files but not all,and moving to other path also had issue.

For your reference I had tried.

#!/usr/bin/ksh
file1=`echo 1234551abcde20140718023216001.txt.809047512.2014_07_07_13:47:44 | awk -F "." '{for(i=1;i<NF;i++) if ($i!= 1) f=f?f FS $i:$i;print f;f=""}'`
echo $file1
share|improve this question
1  
do you have rename by larry wall –  richard Jul 18 at 16:29
    
I didnt use "rename" option Not sure if it will work for multiple files,and then move to other path –  Ankit Jul 18 at 16:39
1  
The rename command I am writing about can do both at same time. (all rename/mv tools I have used on Unix can rename and move at same time). Beware the rename you have may not be the same rename, this one is written in purl written by Robin Barker and Larry Wall. –  richard Jul 18 at 16:48

1 Answer 1

Awk isn't going to make your life easier. You can use the suffix removal syntax: ${x%.*} is the value of the variable x with the shortest suffix of the form .* removed.

for x in *.txt.*.*; do
  mv "$x" "/other/directory/${x%.*}"
done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.