Awk problem: How to express the backtick(')

For example:
I got a list of file end at .txt. I want all of them do the same command like
grep '^@' and attached it to a output .sh file.

This is the command I type:

ls *.txt | awk '{print "grep \' \^\@\' ",$1}' > txt.sh

My desired output is when I type the command "more txt.sh "
The desired output is like this:

sample1.txt | grep '^@'
sample2.txt | grep '^@'
sample3.txt | grep '^@'
sample4.txt | grep '^@'

I got the problem when trying to show out the ' (backtick) at the txt.sh file.
I used the \' to show out the ' (backticks).
Is't because I use wrong?
Thanks a lot for your advice and suggestion.

Why so complicated?

grep '^@' *.txt

Or, if you really want to write a file:

for file in "*.txt"; do echo "grep '^@' $file" >> txt.sh; done

Hi,

After I try this command that you suggested,

for file in "*.txt"; do echo "grep '^@' $file" >> txt.sh; done

It comes out something like :

grep '^@' *.out

But if I try

for file in *.txt; do echo "grep '^@' $file" >> txt.sh; done

It comes out something like:

grep '^@' )' sample1.txt
grep '^@' sample1.txt
grep '^@' )' sample2.txt
grep '^@' sample2.txt
 grep '^@' )' sample3.txt
grep '^@' sample3.txt
 grep '^@' )' sample4.txt
grep '^@' sample4.txt

Can I know why will got four extra file coming out?
Actually my desired output is look like this only:

grep '^@' sample1.txt
grep '^@' sample2.txt
grep '^@' sample3.txt
grep '^@' sample4.txt

Thanks again for your advance :slight_smile:

if you want it the below format

grep '^@' sample1.txt
grep '^@' sample2.txt
grep '^@' sample3.txt
grep '^@' sample4.txt

This should do

ls *.txt|awk '{print "grep \47\^\@\47 " $0}'

Can't see why it wouldn't work:

$ ls -1
sample1.txt
sample2.txt
sample3.txt
sample4.txt
$ for file in *.txt; do echo "grep '^@' $file" >> txt.sh; done
$ ls -1
sample1.txt
sample2.txt
sample3.txt
sample4.txt
txt.sh
$ cat txt.sh
grep '^@' sample1.txt
grep '^@' sample2.txt
grep '^@' sample3.txt
grep '^@' sample4.txt