How to create a shell script that puts an echo at the beginning of each line in a file

1

I need to create a script that inserts the echo command at the beginning of each line of the file and at the end > > blocodenotas, for example

#!/bin/bash
ls -l
uname -a
netstat -tunap

I want a script that turns this into:

echo "#!/bin/bash >> log"
echo "ls -l" >> log"
echo "uname -a" >> log" 
echo "netstat -tunap >> log"
    
asked by anonymous 13.12.2018 / 20:39

2 answers

0

You can use the awk utility to solve your problem with just one line, see:

$ awk '{ print "echo \"" $0 "\" >> log"  }' script.sh > saida.txt
    
19.12.2018 / 19:35
0

With thirst it is also possible:

sed -i -e 's/^/echo \"/;s/$/ >> log\"/'  arquivo
    
20.12.2018 / 12:47