help with perl search/replace regex

S

solaristar

So i have a file with a line

foo_bar_baz (some amount of whitespace) 100 (a number)

I basically want to have a search regex that searches foo_bar_baz(and
then to the end of the line regardless of what text)

and replace it with foo_bar_baz \t (tab) 101 (some dif number

---

my command is as such but isnt working

perl -i -pe 's/minutes_between_backups$/minutes_between_backups
\t1020/' /etc/myconffile*.conf

I thought $ matched to the end of the line?
 
S

solaristar

So i have a file with a line

foo_bar_baz (some amount of whitespace) 100 (a number)

I basically want to have a search regex that searches foo_bar_baz(and
then to the end of the line regardless of what text)

and replace it with foo_bar_baz \t (tab) 101 (some dif number

---

my command is as such but isnt working

perl -i -pe 's/minutes_between_backups$/minutes_between_backups
\t1020/' /etc/myconffile*.conf

I thought $ matched to the end of the line?

figured it out

perl -i -pe 's/minutes_between_backups.*/minutes_between_backups\t
\t1020/' /etc/myconf*.conf

thanks to

http://www.comp.leeds.ac.uk/Perl/matching.html
 
J

Jürgen Exner

solaristar said:
So i have a file with a line

foo_bar_baz (some amount of whitespace) 100 (a number)

I basically want to have a search regex that searches foo_bar_baz(and
then to the end of the line regardless of what text)

and replace it with foo_bar_baz \t (tab) 101 (some dif number

my command is as such but isnt working

perl -i -pe 's/minutes_between_backups$/minutes_between_backups
\t1020/' /etc/myconffile*.conf

/minutes_between_backups/ will never match 'foo_bar_buz'.
I thought $ matched to the end of the line?

It matches the end of the line itself. If you want to match whatever
text between the current position and the end of the line then simply
use '.*'.

jue
 
S

solaristar

/minutes_between_backups/ will never match 'foo_bar_buz'.


It matches the end of the line itself. If you want to match whatever
text between the current position and the end of the line then simply
use '.*'.

jue

yup thanks i figured it out a bit after i posted hehe, i was using the
foo_bar_baz as an example of the text, not as the literal text :)
thanks for the reply though
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top