# Easy question for those who do know PERL

**URL:** <https://boards.straightdope.com/t/easy-question-for-those-who-do-know-perl/211151>\
**Category:** Factual Questions\
**Created:** [November 3, 2003, 2:39pm UTC](https://boards.straightdope.com/t/easy-question-for-those-who-do-know-perl/211151 "2003-11-03T14:39:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SlickRoenick](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@SlickRoenick](https://boards.straightdope.com/u/SlickRoenick)\
**Post date:** [November 3, 2003, 2:39pm UTC](https://boards.straightdope.com/t/easy-question-for-those-who-do-know-perl/211151/1 "2003-11-03T14:39:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![SirRay](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@SirRay](https://boards.straightdope.com/u/SirRay)\
**Post date:** [November 3, 2003, 3:00pm UTC](https://boards.straightdope.com/t/easy-question-for-those-who-do-know-perl/211151/2 "2003-11-03T15:00:44Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![leenmi](https://avatars.discourse-cdn.com/v4/letter/l/f1d935/32.png) [@leenmi](https://boards.straightdope.com/u/leenmi)\
**Post date:** [November 3, 2003, 3:03pm UTC](https://boards.straightdope.com/t/easy-question-for-those-who-do-know-perl/211151/3 "2003-11-03T15:03:57Z")

</div>

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** \*  
**g/STRING/d**

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.

---

<div class="post-metadata">

**Author:** ![SirRay](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@SirRay](https://boards.straightdope.com/u/SirRay)\
**Post date:** [November 3, 2003, 3:11pm UTC](https://boards.straightdope.com/t/easy-question-for-those-who-do-know-perl/211151/4 "2003-11-03T15:11:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![SlickRoenick](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@SlickRoenick](https://boards.straightdope.com/u/SlickRoenick)\
**Post date:** [November 3, 2003, 3:27pm UTC](https://boards.straightdope.com/t/easy-question-for-those-who-do-know-perl/211151/5 "2003-11-03T15:27:07Z")

</div>

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