For example test.txt contains:
Hi
Hello
Hi world
The code below removes a word from test.txt and creates a temp file test_removed.txt which contains the:
#!/bin/bash
echo -n Enter Input:
read input
sed -e "/^${input}/d" test.txt > test_removed.txt
The code below searches for your word and will print it out. For example, if you search "Hi", it will print out "Hi Hi World" exactly like that all in 1 line.
#!/bin/bash
echo -n "Enter Input: "
read input
echo 'grep $input test.txt |awk -F":" {print $0}''
In my code below, I noticed that in the last line of code in the "a" block of code, if instead of making a new line for each of the 6 pieces of information asked of the user, it had it all in 1 line then the code above to remove and search will do it correctly. But since there are multiple lines to remove I'm not sure what to do. To remove, it just asks the user for first and last name. To search it just asks for first name.
#!/bin/bash
ok=0;
while ((ok==0))
do
echo "Main Menu:"
echo -e "\t(a) Add"
echo -e "\t(b) Remove"
echo -e "\t(c) Seach"
echo -e "\t(d) Display contacts"
echo -e "\t(e) Exit"
echo -n "Please enter your choice:"
read choice
case $choice in
"a"|"A")
ok=1
echo -e "[Add c ontact]"
echo -n "First N ame: "
read firstName
echo -n "Last N ame: "
read lastName
echo -n "Phone Number: "
read phoneNumber
echo -n "Address: "
read address
echo -n "Email: "
read email
echo "$firstName $lastName is added to your contacts"
echo -e "First Name: $firstName\nLast Name: $lastName\nPhone Number: $phoneNumber\nAddress: $address\nEmail: $email\n\n" >> ./contacts_firstname
;;
"b"|"B")
ok=1
echo -e "[Remove a c ontact]"
echo -n "First N ame: "
read first
echo -n "Last N ame: "
read last
sed -e "/^${first}/d" contacts_firstname > contacts
;;
"c"|"C")
ok=1
echo -e "[Search c ontacts]"
echo -n "Search by the contact's First N ame: "
read FName
echo 'grep $FName contacts_firstname | awk -F":" '{print $0}''
;;
"d"|"D")
ok=1
;;
"e"|"E")
exit
;;
*)
echo "invalid answer, please try again"
;;
esac
done
echo "You entered $choice"
;
insted of\n
?