I've extrapolated your requirements as best I can from the limited information. This should accomodate exponents to + or - 30 I hope. Requires the bash or ksh shell. It assumes the numbers are in the format [+- ]0.1234E[+- ]00
which will sort cleanly with sort -n then reading it in order to get the filenames and move them.
Code:
#!/bin/bash
OLDIFS="$IFS"
IFS=" _tdatE. "
N=0
for FILE in t_*.dat
do
# Convert exponential notation into fixed point.
# We do this by removing zeroes from the front
# to increase the exponent, adding zeroes to the front
# to decrease the exponent, and padding zeroes onto the
# end to a fixed length. This will produce a number
# that can be sorted.
set -- $FILE
set -- $*
SIGN="+"
if [ "${1:0:1}" = "-" ]
then
SIGN="-"
set -- ${1:1} ${2} ${3}
fi
if [ "${1:0:1}" = "+" ]
then
set -- ${1:1} $2 $3
fi
EXP=${3}
VAL="000000000000000000000000000000${1}${2}"
LEN="${#1}"
while [ "$LEN" -gt 1 ]
do
VAL="${VAL:1}"
let LEN=LEN-1
done
[ -z "$EXP" ] && EXP="0"
# Strip leading zeroes from exponent
while [ "${EXP:0:2}" = "-0" ] ; do EXP=${EXP/-0/-} ; done
while [ "${EXP:0:2}" = "+0" ] ; do EXP=${EXP/+0/+} ; done
[ "$EXP" = "-" -o "$EXP" = "+" ] && EXP=0
# Strip zeroes off the front of the number for positive exponent
while [ "$EXP" -gt 0 ]
do
VAL="${VAL:1}"
let EXP=EXP-1
done
# Add zeroes to the front of the number for negative exponent
while [ $EXP -lt 0 ]
do
VAL="0${VAL}"
let EXP=EXP+1
done
while [ "${#VAL}" -lt 60 ] ; do VAL="${VAL}0" ; done
printf "%s0.%s\t%s\n" ${SIGN} "${VAL}" "${FILE}"
done | sort -n | while IFS="$OLDIFS" read ORDER FILENAME
do
NAME=$(printf "t%05d.dat" $N)
let N=N+1
echo mv "$FILENAME" "$NAME"
done
Hey guys,
I have wrote the following script to apply a module named "trinity" on my files. (it takes two input files and spit a trinity.fasta as output)
#!/bin/bash -l
#SBATCH -p node
#SBATCH -A <projectID>
#SBATCH -n 16
#SBATCH -t 7-00:00:00
#SBATCH --mem=128GB
#SBATCH --mail-type=ALL... (1 Reply)
I have multiple files in folder which i want to rename. hence I am using the below command in my script by I get an error:
export XXX_LOG_DIR="${LOG_DIR}/${XXX_HOST}/xxx/${REPORT_DATE}"
mv $XXX_LOG_DIR/*.audit.gz $XXX_LOG_DIR/*.audit.log.gz
But I get the below error:
mv: target... (5 Replies)
Hi,
I want perl script for the below requirement.
We have lot of files like below name in the directory
750464921-RE-file2.csv
750452173-RE-file1.csv
750385426-RE-file3.csv
750373470-RE-file4.csv
And also we have another file as "Group.csv" in the same directory as per the below format... (9 Replies)
Hey guys, I am the definition of a newbie. I am in the process of trying to rip all my dvds onto a new HTPC I setup. While doing this, I am also trying to organize a bunch of other files I already have to proper naming conventions. So far I have just been naming each file separately (I am on a... (4 Replies)
Hi
I need to reanme the multiple file using unix script
I have multiple file
like:
sample_YYYYMMDD.xls
test new_YYYYMMDD.xls
simple_YYYYMMDD.xls
I need to rename this file
sample.xls
testnew.xls
SIMPLE.xls
thanks (8 Replies)
Hi everyone,
I'm very green in Linux.
Please help me to solve my problem.
I have thousands of files and I want to change their names.
They have naming convection: prefix_date_date+1_suffix.nc
prefix: ext-GLORY
date_date+1: 20020101_20020102
and two types of suffix: gridV_R20020130 and... (3 Replies)
Hi all, I have some files like:
pickup.0000043200.t001.t001.data
pickup.0000043200.t001.t002.data
pickup.0000043200.t002.t001.data
pickup.0000043200.t002.t002.data
pickup.0000043200.t003.t001.data
pickup.0000043200.t003.t002.data
I need to rename these files to
... (4 Replies)
Hi all, I have some files like:
pickup.0000043200.t001.t001.data
pickup.0000043200.t001.t002.data
pickup.0000043200.t002.t001.data
pickup.0000043200.t002.t002.data
pickup.0000043200.t003.t001.data
pickup.0000043200.t003.t002.data
I need to rename these files to
... (3 Replies)
Hello,
I want to rename multiple files at a time and I don't know how to do it.
I have various ".mp3" files, like "band name - music name.mp3" and I want to remove the "band name" from all files.
Anybody knows how to do it using shell script or sed or even perl?
Thanks (7 Replies)