awk command in special character

Hi,

I want to add below line after end of a file (i.e file1)

&&echo "copy done" >> out.txt

 
cat file1
scp user1@server1:/tmp/dir /tmp/dir1

my requirment is

 
cat file1
scp user1@server1:/tmp/dir /tmp/dir1 &&echo "copy done" >> out.txt

could any one please help me

Thanks

What's the "cat file1" for?

What do you need help with? You seem to have already been given the answer...

actually I am runing command

# cat file1
/tmp/dir1/A1
/tmp/dir1/A2

# awk '{print $1 " \&&echo "scp done" >> out.txt"}' file1 > file2
awk: warning: escape sequence `\&' treated as plain `&'

# cat file2
/tmp/dir1/A1 &&echo  >> out.txt
/tmp/dir1/A2 &&echo  >> out.txt

but I want output as

/tmp/dir1/A1 &&echo "scp done" >> out.txt

You want that output? Or you want that command to be run?

Because you haven't used code tags it's almost impossible to tell the difference between your files and your shell statements.

ohh ..sorry ..!!
is it clear now?

actually I am runing command

# cat file1
/tmp/dir1/A1
/tmp/dir1/A2
# awk '{print $1 " \&&echo "scp done" >> out.txt"}' file1 > file2
awk: warning: escape sequence `\&' treated as plain `&'  --> this warning i am getting
# cat file2
/tmp/dir1/A1 &&echo >> out.txt
/tmp/dir1/A2 &&echo >> out.txt

but I want output as

#cat file2
/tmp/dir1/A1 &&echo "scp done" >> out.txt
/tmp/dir1/A2 &&echo "scp done" >> out.txt

You certainly don't need to build shell scripts inside awk to do that.

while read LINE
do
        "$LINE" && echo "$LINE:  scp done"
done < file1 > out.txt
1 Like
awk '{print $1 " &&echo \"scp done\" >> out.txt"}' file1 > file2
1 Like

Thanks ..!!

Both command worked fine :slight_smile: