user1734552
user1734552

Reputation: 21

Pull part of string using regExp in perl

Small question regrading taking part of string. my string is

some text here value: 100 .1.3.6 bla bla.

I would like to save the first part of the sting till the .1.3.......

so at the end ill have only

some text here value: 100

Upvotes: 0

Views: 98

Answers (2)

Steve
Steve

Reputation: 54392

This may be what you're looking for (assuming there's only one : per line).

perl -pe 's/(.*: [^ ]+).*/$1/' file.txt 

Result:

some text here value: 100

Upvotes: 1

JRFerguson
JRFerguson

Reputation: 7516

$str="some text here value: 100 .1.3.6 bla bla.";$str=~m{^([^.]*)} and print $1'

This matches from the beginning of the string until a dot character appears. The matched portion is captured and printed if there was a match.

Upvotes: 1

Related Questions