Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How I search for strings with HTML tag like

< link type="text/css" rel="stylesheet" 

In a index.html file and replace that with

<link type="text/css" rel="stylesheet" 

Note: I just want to insert 'S' in between teststore.

I did achieved that with perl syntax as

perl -i -p -e 's/teststore/testsstore/ if ($. == 28 || $. == 41)' index.html

My only concern is if the index.html file changes then the line number too will get change.. i dont want my script to exit. instead i need a way to search based on text strings instead of line no.

Any idea how to achive this.. A little brief would be highly helpful.

share|improve this question

What you're looking for can be achieved by using "Regular Expressions" or short "Regex". With them you can search for certain text patterns and modify them. It's like a specific language designed to solve "pattern match" and "find & replace" problems mostly used in string parsing.

Perl is actually quite formidable with them as they are integrated in the language itself.

You can find overview e.g. at

If you prefer a book: (it covers other programming language as well, but mostly covers perl)

Also, as this is a programming topic, you might want to head over to and see if anyone has asked anything similar there.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.