I would use something like this:
alias search_and_append {
var %regex_text = Charlie
var %file_search = texto.txt
var %append_text = New Text
var %read_text = $read(%file_search,r,%regex_text)
if (%read_text) {
echo -a Found at line: $readn $+ , appending to line...
write $+(-l,$readn) %file_search $+(%read_text,$chr(9),%append_text)
}
else {
echo -a Pattern not found, sorry.
}
}
I used $chr(9) (Tab) as separator (Just because it looks fine).
And here my file texto.txt
BEFORE:
Alfa 6 7
Bravo 5 5
Charlie 4 9
Delta 3 10
Echo 1 2
Foxtrot 2 4
And
AFTER using the script:
Alfa 6 7
Bravo 5 5
Charlie 4 9 New Text
Delta 3 10
Echo 1 2
Foxtrot 2 4
Of course you can use $numtok for watching if all parameters are already in the line (If you don't want to add any other parameter).
You can use
regex syntax for searching starts of line:
And if you want case-insensitive I would use:
And both (maybe what you are searching for, but using tabs as separators):