help with finding text and deleting line

HI All, I need to search for a particular pattern input by the user in order to delete the line. My username.txt has

username@email.com:John:149.0.3.4:1
username1@email.com:Harry:149.0.3.4:1
username1@email.net:Alex:149.0.3.4:1
username1@email.edu:Nemo:149.0.3.4:1

The program i written

#!/bin/bash

echo " Insert email"
read a
echo "Insert name"
read b

if i input username@email.com and John, the output should be

username1@email.com:Harry:149.0.3.4:1
username1@email.net:Alex:149.0.3.4:1
username1@email.edu:Nemo:149.0.3.4:1

I tried sed, but it only reads from a defined variable. Any help would be appreciated, thanks

Hi,
Try this,

#!/bin/sh

echo -n "Enter email:-"
read a
echo -n "Enter name:-"
read b

c="$a:$b"

grep -v "$c" username.txt
1 Like

Or:

awk -F: 'BEGIN{
  printf("Enter the email and username :")
  getline ans < "-"
  split(ans,a," ")
}
!(a[1]==$1 && a[2]==$2)
' username.txt
1 Like

Hi, That worked, thanks!

I have 3 questions
Question 1 how can i set up such a way that when i input a,b, it only prints out that line ( kinda like search function)

e.g
username.txt

username@email.com:John:149.0.3.4:1
username1@email.com:Harry:149.0.3.4:1
username1@email.net:Alex:149.0.3.4:1
username1@email.edu:Nemo:149.0.3.4:1 

if i input username@email.com as a, John as b
Output

username@email.com:John:149.0.3.4:1 

Question 2 How do i only modify the value specified by the user?
e.g

#!/bin/bash


echo -n "Please enter email u which to modify:"
read a
echo -n "Please enter his name:-"
read b
echo -n "Enter new email:-"
read c
echo -n "Enter new name:-"
read d
echo -n "Enter new IP address:-"
read e
etc.. etc..

if a =username@email.com, b = John, c = Hello@yahoo.com, d = Lala, e =127.0.0.1
Output

Hello@yahoo.com:Lala:127.0.0.1:1
username1@email.com:Harry:149.0.3.4:1
username1@email.net:Alex:149.0.3.4:1
username1@email.edu:Nemo:149.0.3.4:1

Advanced Feature , how can i set up in such a way that if i input non characters(like numerals or weird symbols like !@#) for the input a and b, it returns a error message?