天天看點

linux多行檔案資訊追加

方法一:使用echo

++++++++++++

#!/bin/bash

echo "123

  456

     789

123

`ls`">>test.txt

方法二:使用cat(也可以直接指令行手打了)

cat <<ENDOF >>test.txt

1234

   456

`ls`

ENDOF

cat a.sh

cat << EOF >> $1 

define service{

        use                     generic-service

`egrep "^[^#].*host_name" $1 |tail -1`

        service_description     Physical Memory

        check_command           CheckWindowsPhysicalMem!80!90

}

        use                     lg-service,srv-pnp4

        service_description     E:\ Drive Space

        check_command           check_nt!USEDDISKSPACE!-l e -w 80 -c 95

EOF

for i in `ls *.cfg`;do ./a.sh $i;done

本文轉自leonardos51CTO部落格,原文連結:http://blog.51cto.com/leomars/1891403 ,如需轉載請自行聯系原作者

繼續閱讀