Hi...
I have a folder /home/data ;where some files are present.
aaa_asas.txt
bbb_xxx.txt
ccc_xsxas.txt
ddd_sa2esa.txt
------
Also I have a file which is as follows.(/home/file1)
cat /home/file1
aaa you
bbb are
ccc very
ddd good
--------
now I want to rename all the files in the folder /home/data as below
you_asas.txt
are_xxx.txt
very_xsxas.txt
good_sa2esa.txt
In simple terms the script need to read each line (eg:- aaa) and match the pattern in the folder and if it exists it should rename with second column name (eg:- you)
can any body help me plzzzz.i m very new to scripting..
Remove the echo from the awk system() function before executing or it will simply echo the command (good...if you want to see what the final result would be like).
cd /home/data
ls *.txt | awk '{
f = $0
if (NR != FNR) {
split(f, s, /_.*/)
sub(s[1], "", f)
if (s[1] in t)
system("mv "$0" "t[s[1]]""f)
} else
t[$1] = $2
}' file -