-1

How I search for strings with HTML tag like

< link type="text/css" rel="stylesheet" 
                href="https://teststore.xxxx.com/gwtstore.css"> 

In a index.html file and replace that with

<link type="text/css" rel="stylesheet" 
                href="https://testsstore.xxxx.com/gwtstore.css">

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.

1 Answer 1

2

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 http://www.troubleshooters.com/codecorn/littperl/perlreg.htm

If you prefer a book: http://regex.info/ (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 stackoverflow.com and see if anyone has asked anything similar there.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .