mercredi 25 mars 2015

Remove paragraph from file


I have a file (file.php) like this:



...
Match user foo
ChrootDirectory /NAS/foo.info/
ForceCommand internal-sftp
AllowTcpForwarding no
GatewayPorts no
X11Forwarding no



Match user bar
ChrootDirectory /NAS/bar.co.uk/
ForceCommand internal-sftp
AllowTcpForwarding no
GatewayPorts no
X11Forwarding no



Match user baz
ChrootDirectory /NAS/baz.com/
ForceCommand internal-sftp
AllowTcpForwarding no
GatewayPorts no
X11Forwarding no


I am trying to write a bash script to delete one of the paragraphs.




So say I wanted delete the user foo from the file.php. After running the script, it would then look like this:



...
Match user bar
ChrootDirectory /NAS/bar.co.uk/
ForceCommand internal-sftp
AllowTcpForwarding no
GatewayPorts no
X11Forwarding no



Match user baz
ChrootDirectory /NAS/baz.com/
ForceCommand internal-sftp
AllowTcpForwarding no
GatewayPorts no
X11Forwarding no


How could I go about doing this. I have thought about using sed but that only seems to be appropriate for one liners?



sed -i 's/foo//g' file.php


And I couldn't do it for each individual line as most of the lines withing the paragraph are not unique! Any ideas?



Aucun commentaire:

Enregistrer un commentaire