linux系统在脚本里面怎么给一个文件追加几行内容

linux系统在脚本里面怎么给一个文件追加几行内容,第1张

#!/bin/sh

echo "asfsaf

gfsfdsf

asfasdas

gds

fs

f" >>123.txt

输入到要换行的地方直接回车就行了,记得双引号引出

sed -i '1{s/.*/&123/}' /etc/hosts  #修改并保存

[root@localhost 10]# sed '1{s/.*/&123/}' /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4123

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

试下这个:

#!/bin/bash

awk '{

if(NR==1){

str=$0

} else {

if($0 ~ /^[[:space:]]+/)

str=str "\t" gensub(/^[[:space:]]+/, "", "", $0)

else

str=str "\n" $0

}

}

END{

print str

}' /jiankong/diskcheck_tmp


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8388787.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-15
下一篇 2023-04-15

发表评论

登录后才能评论

评论列表(0条)

保存