Question : Removing multiple lines from a file with Bash Script

I need to remove multiple lines from /etc/fstab, and if a match is found the lines need to be echoed.

The content in /etc/fstab is :
/dev/sda1 /     ext3    defaults 1 1
/dev/sdi /db xfs noatime 0 0
/dev/sdk3 /web xfs noatime 0 0
/dev/sdk1 /web xfs noatime 0 0

I would like to remove " /web " which is in a variable.

Answer : Removing multiple lines from a file with Bash Script

there are no regex involved - its a simple pattern match and grep would work fine

#!/bin/bash

#this line would output all lines that do NOT have " /web " and store them in a file called output in current working directory
grep -v " /web " /etc/fstab  > outfile

echo "Lines removed from fstab"

#this line would print all lines that have " /web "
grep " /web " /etc/fstab

#uncomment this line if you wish to replace /etc/fstab with the output file.
#mv outfile /etc/fstab
Random Solutions  
 
programming4us programming4us