Need help in scripting ...

****************************************************
grep -l $Timestamp `ll|grep "$1 $2 $3"|awk '{print $NF}'` >Files.txt

#The indentified files were written to Files.txt

for i in `cat Files.txt`

do
#Copies indentified files as Lin_filename

cp -p $i $Lin\\_$i

\#Moves Lin_filename files to MQ retry directory

mv $Lin\\_$i /merccesar/data/router/inMqR/retry/

done
******************************************************

If you see here I am writting the result of grep -l $Timestamp `ll|grep "$1 $2 $3"|awk '{print $NF}'` into a file.

and then copying and moving the files in the Files.txt.

Instead of loop I want to store the value of *** grep -l $Timestamp `ll|grep "$1 $2 $3"|awk '{print $NF}'` *** into a variable and then copy and move ...

But :frowning: when I tried the below command

Var=`grep -l $Timestamp `ll|grep "$1 $2 $3"|awk '{print $NF}'``

It is not getting executed :frowning:
Please help me !!!

Thank You
Subbu

This maybe because you are nesting backquotes.

try (in Bash anyway):

Var=$(grep -l $Timestamp $(ll|grep "$1 $2 $3"|awk '{print $NF}'))

Though that method may introduce other problems because I think the $(..) syntax executes the commands in a subshell.

*********************************************************
Var=`ll|grep "$1 $2 $3"|awk '{print $NF}'`

Var1=`grep -l $Timestamp $Var`

\#Copies indentified files as Lin_filename

cp -p $Var1 $Lin\\_$Var1

\#Moves Lin_filename files to MQ retry directory

mv $Lin\\_$Var1 /merccesar/data/router/inMqR/retry/

*******************************************************
This worked out :smiley:

Thank You
Subbu