Easy question for those who do know PERL

A friend wrote a little script for me a while back which filters an error log. I need to take out one of the strings it searches for. This is on a UNIX machine. I can get into the program if i type
vi errorscan*

and once the code is showing i can edit stuff if i press i, but that’s about the extent of my knowledge working with Perl. The backspace button doesn’t work and i don’t know how to delete the string and then save/exit the program. Help please.

Sounds like more of a vi question than a perl question.

Do you only one want to remove one line?
If so
vi errorscan, then do not hit i, but instead do /‘string to search for’
Where the ‘string to search for’ is basically the line you want to delete,
then dd
then save.

Heck, you could even cat errorscan | grep -v ‘string to search for’ > errorscan.new, then mv errorscan.new to errorscan if you wanted to…

Remember to make backups first!

Until you learn more about vi, you might want to use a text editor like kate or kedit. (Assuming Linux.) Or start with vimtutor.

But, for your question, there are several ways to do it. First, copy the file:

cp errorscan errorscan.110303*

If it is possible to find a unique word or phrase in the string, and the string is on its own line, you can simply delete the string.

vi errorscan*

If it is not on its own line, use the backslash “/” to search for the string. If it appears more than once, the “n” key will go to the next instance. Use the h,j,k and l keys to move right, down, up and left. Use the “x” key to remove one character at a time.

When done, hit the Escape key. Then type “:wq” to write and save your exits. If you need to close the vi session without saving, type :q!

Someone will be along shortly with more whizbang ways of doing it. I tried to keep it simple for you.

You know, I probably screwed you up in that last post…
It’s OK if you want to delete one LINE (example: delete Wheee)

next if m/Whoopi/;
next if m/Wheee/;
next if m/Wow/;

Here, you just find the line via /Whee while in vi, but not in edit mode, then type dd, and finally save (:w!).

But if you need to edit further

next if m/Wheee/ || m/Whoo/;

Then you can use x to delete one letter (under the cursor) at a time to remove (example) m/Wheee/ || to yield

next if m/Whoo/;
Note: u will undo the last operation only, so if you accidently delete i in if, type u to get it back

Again, save via :w!

If it’s an array or hash, or a more complex if statement well then you can still edit via x, but if its the last element you may have to use insert mode - hard to tell without more info.

Cool, I used a combination of SirRay’s and leenmi’s replies. Thanks folks