#!/bin/ksh
for i in *.txt; do
[[ "$i" = */* ]] && path="${i%/*}" || path="."
file="${i##*/}"
base="${file%.*}"
ext="${i##*.}"
new=$(printf "%s/%s-%04d.%s" $path ${base%-*} $((${base##*-}*2-1)) $ext)
# remove echo cp if you feel result is as expected
echo cp $i $new
done
There's a file Alk-0002.txt already, right? What do you think it will happen if you
Alk-0001.txt > Alk-0002.txt
And then you
Alk-0002.txt > Alk-0004.txt ?
You will be practically overwriting files right and left.
Any solution presented must have that in consideration. I think it would have to be a two pass renaming in order to be safe.
Let me show you how to test safely
Code:
mkdir working_dir && cd working_dir
touch Alk-{0001..0067}.txt
Now, you have a dummy army of files to test.
cp the script to this file and execute it only when you are cd into.
Now a possible solution for the first request
Code:
#!/bin/ksh
change_serial() {
for f in Alk-*.txt; do
fnameplus=${f%.*}
ext="${f##*.}"
serial="${fnameplus##*-}"
case "$1" in
1)
trim_serial=$(printf "%010d" "$((serial*2))");
;;
2)
trim_serial="${serial:6}"
;;
*)
echo "bailing out";
exit 1;
;;
esac
mv "$f" "Alk-${trim_serial}.${ext}"
done
}
change_serial 1
change_serial 2
Last edited by Aia; 10-09-2014 at 02:40 AM..
Reason: ksh
I created this script for check whether specific files exist or not in the given location. but when I run this its always showing
Failed - Flag_lms_device_info_20160628.txt do not exist
Failed - Flag_lms_weekly_usage_info_20160628.txt do not exist
but both files are existing. appreciate help... (2 Replies)
#!/bin/bash
#
name=$1
type=$2
number=1
for file in ./**
do
if
then
filenumber=00$number
elif
then
filenumber=0$number
fi
tempname="$name""$filenumber"."$type"
if (4 Replies)
Hi All,
I have 100 files named - rep-0.txt, rep-2.txt...rep-99.txt.
They each contain information in the following format:
abc 1 qwe
asd 2 zxc
poi 3 lkj
pdh 4 ldf
hgf 5 tyu
i would like to re-number , so that all the new files (rep0.dat, rep1,dat....) have... (1 Reply)
I have a fasta file that looks like this:
>Noname
ACCAAAATAATTCATGATATACTCAGATCCATCTGAGGGTTTCACCACTTGTAGAGCTAT
CAGAAGAATGTCAATCAACTGTCCGAGAAAAAAGAATCCCAGG
>Noname
ACTATAAACCCTATTTCTCTTTCTAAAAATTGAAATATTAAAGAAACTAGCACTAGCCTG
ACCTTTAGCCAGACTTCTCACTCTTAATGCTGCGGACAAACAGA
...
I want to... (2 Replies)
Hi,
I am a beginner in awk scripting! I need your help; I want to replace the fifth column number (which is 15 here) here in this file for example :
ATOM 142 N PRO A 15
ATOM 143 CD PRO A 15
ATOM 144 HD1 PRO A 15
ATOM ... (5 Replies)
I wrote script in bash which generates this report "users.csv":
I wrote script in bash which generates this report "groups.csv"
I want to integate two reports: "users.csv" and "groups.csv".
I want like so that "result.csv": (2 Replies)
I wrote script in bash which generates this report "users.csv":
I wrote script in bash which generates this report "groups.csv"
I want to integate two reports: "users.csv" and "groups.csv".
I want like so that "result.csv":
Thx (5 Replies)
I am new to the world of UNIX scripting - and would like to make the following script:
I have 100 files numbered 1-100. However - i would like to continue the file list - so that I add another 100 files following on, so that file 101 = 99; file 102 = 98 ; 103 = 97 and so on....
(basically ...... (6 Replies)