+ -
当前位置:首页 → 问答吧 → shell文本删除问题求助

shell文本删除问题求助

时间:2011-09-18

来源:互联网

请问如何使用shell脚本删除samba的配置文件中的一个用户子项啊? samba的配置文件信息如下所示:

[global]
  workgroup = MYGROUP
  security = user

[user1]
  path = /home/user1
  public = no 
  writeable = yes  
  browseable = yes
  valid users = user1
   
[user2]
  path = /home/user2
  public = no 
  writeable = yes  
  browseable = yes
  valid users = user2

[user3]
  path = /home/user3
  public = no 
  writeable = yes  
  browseable = yes
  valid users = user3

现在需要写一个shell脚本userdel.sh, 传递一个参数, 譬如参数为user2, 执行sh userdel user2之后, 将从上面的samba配置文件中把user2的信息删除, 删除后的内容变为:
[global]
  workgroup = MYGROUP
  security = user

[user1]
  path = /home/user1
  public = no 
  writeable = yes  
  browseable = yes
  valid users = user1

[user3]
  path = /home/user3
  public = no 
  writeable = yes  
  browseable = yes
  valid users = user3

请问这个shell脚本该怎么写啊? 哪位高手可以帮帮忙? 万分感激!!

作者: linux_6   发布时间: 2011-09-18

grep -n userN,获取所在的行号,假如获取的是10行,再用删除行sed -n '10,15p' 配置文件.ini

作者: wangtingguang   发布时间: 2011-09-18

错了,删除是sed -n '10,15d'

作者: wangtingguang   发布时间: 2011-09-18