I'm aware of similar questions of this topic, but none of them actually answered the question the way I wanted.
My code:
$answer = 1
DO {
Write-host "What u want?"
Write-host "1.Add note"
Write-host "2.Read notes"
Write-host "3.Exit"
$answer = Read-host Write a number between 1 to 3 and press Enter.
if ($answer -eq 1)
{
DO {
$msg = Read-host Write the note and press Enter:
$path = Get-Location
Add-content $path\"DONTREMOVEME.txt" "- $msg"
$res = Read-host "Added, want to add one more? y/n"
}
while ($res -ne "n")
Write-host "...back to the main menu"
Start-Sleep -s 2
}
if ($answer -eq 2)
{
$path = Get-Location
Get-content $path\"DONTREMOVEME.txt"
Read-host "Press Enter to go back to the main menu"
}
} While ($respuesta -ne 3)
Write-host Bye.
I really need to add a "delete notes" option but I have no clue and tried with sed, grep, get-content replace etc.
I need an option in the table that asks the user for a note (line) that wants removed (not in blanck, removed) after showing the list available (with cat, maybe?).
Something like:
if ($answer -eq 3) #let's say 'Exit' is now 4th option
{
$path = Get-Location
Get-content $path\"DONTREMOVEME.txt" # or cat $path\"DONTREMOVEME.txt"
$delete = Read-host which note you want removed? Type the number and press Enter
#and actually deleting it.
}
Thank you so much in advance.
* EDIT: I'm so sorry, maybe I explained myself very poorly.
I don't want the code to check a matching string given by the user (that's why the previous questions and answers of stack overflow didn't actually work for me).
The notes inside the DONTREMOVEME.txt could be e.g.:
- Buy salt
- Buy bags
- Remember to feed cats
- Go for a walk
And the code has to display that and ask the user which line wants deleted (because the activity it's already done) as an int.
So user presses "3" and Enter, so "Remember to feed cats" disappears like this:
- Buy salt
- Buy bags
- Go for a walk
Searching for a matching string does not work because the variety and extension of the notes can make difficult to pinpoint 1 word and being sure it doesn't appear in another line...
Also, can't use a $count++ to every line so the user can use to match strings like this:
1 Buy salt
2 Buy bags
3 Remember to feed cats
4 Go for a walk
...because in the notes can be written "buy 2 bags".
I hope I made myself clear this time, I'm so sorry for the caused trouble.