rename file

Hi,

I have files in the format

thread_1_seq_1965.440.755943413
thread_1_seq_1966.577.755943443
thread_2_seq_2034.383.388388888

I want to rename this in the form of

1_1965.arc
1_1966.arc
2_2034.arc

Discard everything except the [8-9] th char and [14-17]. The character position remains the same.

How can i do this using awk/sed or any other command

Hi

$ for i in thread*
> do
>  x=`echo $i | cut -c 8-9,14-17`".arc"
>  mv $i $x
> done
$ ls *arc
1_1965.arc  1_1966.arc  2_2034.arc

Guru.

1 Like
ls thread* | awk '{print "mv "$1" "substr($1,8,2)substr($1,14,4)".arc"}' | sh
1 Like

In ksh93:

for i in thread*
do
 mv $i ${i:7:2}${i:13:4}.arc
done
1 Like