Help needed ....

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.. :frowning:

Pleasehelp me :frowning: :frowning: :frowning: :frowning:

cd /home/data

ls *.txt | awk '{
   if (NR != FNR) {
      split($0, s, "_")
      if (s[1] in t)
         "mv "$0" "t[s[1]]"_"s[2] | getline
   } else
       t[$1] = $2
}' /home/file1 -

It works perfectly ...
however...
what should i do if my file name (in /home/data) is like the following.
qwerty_asdfg_0010_12.txt

and the home/file is
qwerty Thankyou

so that i will get the result as Thankyou_asdfg_0010_12.txt

newbee1,

It's against our rules to bump up questions, please read the:

Regards

cd /home/data

ls *.txt | awk '{
    f = $0
    if (NR != FNR) {
        split(f, s, /_.*/)
        sub(s[1], "", f)
        if (s[1] in t)
            system("echo mv "$0" "t[s[1]]""f)
     } else
         t[$1] = $2
}' file -

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 -

Thanx alot...it works well:b: