2

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

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
  • 1
    do you have rename by larry wall – ctrl-alt-delor Jul 18 '14 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 '14 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. – ctrl-alt-delor Jul 18 '14 at 16:48
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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