Programming :: Perl Regex Not Matching Across Multiple Lines Despite Ms Flags / Fix It?

Aug 16, 2010

I have written a regular expression (tested in regexpal and regextester alpha something) with which I want to replace something like code...

but it only matches functions which occupy one line only, despite my tests showing multiple line matching in javascript testers online and using the m and s flags (which should make it multi line no?)

View 14 Replies


ADVERTISEMENT

Programming :: Perl Regex Matching HTML?

Mar 19, 2010

I'm trying to find out how to extract the string between the 2 <title> tags: <title>this is what i want</title>.I found lots of results but nothing I've tried works.. EG:$page =~ m/<title>($.)</title>/gism;

View 2 Replies View Related

Programming :: Perl Only Matching Single-character Regex Patterns?

Jan 20, 2009

I'm having a small issue with regex matching in Perl. I'm pretty certain it's a simple fix, but it all looks correct to me...

If I run the following:

Code:

It prints out all the lines containing a 'P', as one would expect. But when the regex is

Code:

I get zero lines printed. It seems to match only single-character patterns.

The file I'm reading is: (It has the same effect whether I leave it with Windows linebreaks or convert them to unix).

Code:

View 3 Replies View Related

Programming :: Delete Multiple Lines In A File Using Perl?

Apr 15, 2011

I have a file looks like the following:

digraph topology
{
"192.168.3.254" -> "10.1.1.11"[label="1.000", style=solid];
"192.168.3.254" -> "10.1.1.12"[label="1.000", style=solid];

[code]...

Order of these lines are random... So I cannot delete line #19, for example... And you can see that top four lines I want to delete are pairs. So there might be some clever way to detect the lines, if a line has both "1.9" and "1.11", then delete the line... I am new to perl language. The following is the code I have now... I think I just need to write some code inside the while loop checking if I want to delete the line $dotline before I write to a NEW file.

Code:

#!/usr/bin/perl -w
$TOPPATH = "/tmp";
$NAME = "topology";
$FILENAME = "$TOPPATH/$NAME.dot";

[code]....

View 16 Replies View Related

Programming :: Unable To Match Across Multiple Lines In Perl

May 11, 2011

I'm trying to split a text file into various parts. Everything in between "123" and "break" (including linebreaks) goes into the splitted file.

e.g. using this text file:

This should split into 4 files. However I'm only getting 2 files: one for the line "123break" and one for "123 blah break". The two occurrences that contain linebreaks are being ignored. The .* part of my match should capture linebreaks seeing that I'm using the /s modifier shouldn't it? Even when I use the match /(123 break)/gs it still doesn't capture the first occurrence. I'm using Perl v5.12.3 (from ActiveState) on Windows XP. The text file is also in Windows format.

Code listed below.

The above code generates two files Output_1.txt and Output_2.txt which contain "123break" and "123 blah break" respectively. I want it to generate four files.

View 4 Replies View Related

Programming :: [Perl] Fail To Sort A File With 300,000 Lines By Multiple Columns?

Nov 10, 2009

Each line of the file I am sorting is in the following format:

<url> <month> <day>

For example:

[URL]

I wrote the following to sort:

Code:

#!/usr/bin/perl
$in = shift;
chomp($in);

[code]....

The script worked fine for my small testing files, but failed in my input file. The input file is 18MB and containing more than 300,000 lines. The output will contains some lines like that:

url_one 10 1
url_two 10 1
url_three 10 3
url_four 10 1

Is that because my file is too big for perl to handle ?

View 10 Replies View Related

Programming :: ! For Not Matching Bash Regex?

Jan 13, 2011

In a bash-script, only the case if a regular expression does not match is relevant.herefore I used the exclamation mark !. But where to place it?

These two work fine, but are they equivalent?
Code: if ! [[ $abc =~ $pattern ]]; then or
Code: if [[ ! $abc =~ $pattern ]]; then Where is the ! placed more correct?

View 2 Replies View Related

Programming :: Specific Regex Pattern In Perl?

Feb 23, 2011

I'm fairly new to Perl and regular expressions. I have a large collection of files with their file names in the following general format: string - another string with spaces (2004) [year].ext I would like to know how I could create a regex to separate out:

the first string
another string with spaces
year
extension

If you know of a better way of doing it without regular expressions, I would be happy to hear that way too.

View 13 Replies View Related

Programming :: Insert A Variable Into A Regex In Perl?

Jan 17, 2010

I was wondering if you insert a variable into a regex in Perl, will the contents of the variable be expanded by the regex engine?

View 14 Replies View Related

Programming :: Perl - Regex With Array Elements?

Mar 13, 2011

I have .txt.gz files that store queries made on a browser, d my job is to analyze them.The information is stored in a xml-like style.Quote:

<browser>lwp-trivial/1.41</browser>
<http_code>200</http_code>
<keywords />

[code]...

View 6 Replies View Related

Programming :: Include A String Variable In A Regex (Perl)

Jan 9, 2010

how do you include a string variable as part of a regex in Perl?

View 5 Replies View Related

Programming :: Use Perl Regex To Extract The Hostname From A FQDN?

Nov 19, 2010

How do i use perl regex to extract the hostname from a FQDN?

I have

Quote:

$host=ganymede.a.linux.com
$host=io.a.linux.com
$host=europa.a.linux.com

i just want the characters which are to the left of the first .(dot) in FQDN name. I could get it using substr and split function,but how do i get it through regex.

View 13 Replies View Related

Programming :: Construct A Quick Regex That Will Search For Six Lines Of Text

Apr 25, 2011

I am trying to construct a quick regex that will search for six lines of text without a clear line break between them. It only needs to search, not replace, as I will be using in gEdit (with regex plugin) anyway.

It's for editing subtitle files. The video player I will be using them on can only cope with 3-line subtitles, so I just need to edit any in the srt file that contain four or more. There won't be many so I can do it manually. For example:

26
00:01:47,357 --> 00:01:49,359
a motivated business
professional with
clearly defined goals.

[Code].....

but .* seems to mean "any character, or none", so that doesn't work. My experience of regular expressions is limited, but I do know they are very powerful when used correctly!

View 10 Replies View Related

Programming :: Use Regex In Perl Script To Detect Allowed Words From The File And Then Print Output To The Screen?

Oct 4, 2010

Its my first post in here so please be patient I am trying to use regex in perl script to detect allowed words from the file and then print output to the screen.

As an example : I have text file with orders and returns :

Item2-SKU-2-11.08.2010-online
Item3-SKU-3-11.09.2010-return
Item4-SKU-4-11.09.2010-store

My question: is it possible to make sure that i am ony outputing to the screen orders based on few conditions like Item,order form e.g. online.And is it possible to have multiple matches (Item2 only diplay if ordered online etc)

View 1 Replies View Related

Programming :: Sed Regex Get Multiple String Match In Array?

Apr 8, 2011

I have a sed match that matches for certain string of a regex expression:

Code:
tname=$(echo "$contents" | sed -n 'some pattern')

How do I match for multiple strings in the $contents and return them as an array? for example

Code:
contents="this is a text, just to match patterns, here is another text to be matched"
the sed func would be able to recognize both "text"s, but only one is outputted?

Possible to put it in an array? so ${bar[0]} gives one and ${bar[1]} gives another

View 3 Replies View Related

Programming :: AWK (or TCL/TK): Matching Rows And Columns Between Multiple Files?

May 26, 2011

I've been hitting my head against a wall for awhile with this one:As the last part of some data analysis I performing I would to construct a matrix from a series of different files. These files have the format:

file 1 file 2 file 3
AAAAA .1 AAAAA .1 BBBBB .1
BBBBB .2 BBBBB .1 CCCCC .9

[code]...

View 6 Replies View Related

Ubuntu :: Text Manipulation - Regex - Pattern Matching?

Jul 12, 2010

Are there some good tutorials or reference materials on how do pattern matching and text manipulation in Linux?I have a few simple tasks I'd like taken care of...like formatting numbers in file names, stripping some text from directory names, etc

View 2 Replies View Related

Ubuntu :: Bash - Delete First File Matching Regex?

Mar 27, 2011

In a bash shell script, I want to do something like this:

Code:
if [[ $(ls -ld /some/dir/foo_* | wc -l) -gt 4 ]]; then
rm -rf first_match_of /some/dir/foo_*

[code]....

View 6 Replies View Related

Programming :: Multiple Line Pattern Matching And Variable Extraction?

Oct 19, 2010

I have this complex log file filled with entries like

test1-G1/0/0-100-QOS-7001923-ROUTING (ClassMap)
Action: Resolved New
sysName: test1.local

[code]...

View 1 Replies View Related

Programming :: Blank Lines In A Perl Script?

May 4, 2011

there is a way to add line spaces when asking for user interaction in a script. For example:

Code:

SPACE
Hello what is your name?
SPACE
SPACE

So this is asking a question but has a space/empty line at the top of the screen and 2 spaces/empty lines below. I've seen it done in a bash script using for each line/space needed

Code:

echo ""

So what does perl use?

View 5 Replies View Related

Programming :: Reading Lines Within A File (Perl)?

Mar 16, 2011

I am trying to read certain lines within a file and give the output of the certain lines that dont equal my value, I think showing you would be easier. There is multiples of these inside one file...

Code:

LV Name /dev/vg00/lvol1
LV Status available/syncd
LV Size (Mbytes) 300lable/syncd

[code]....

I want to read everything in the file, if the status is not available then it should display the name (directly above status). If they are all availbale then do nothing. I think I know how to do it which includes putting the info in string form and placing in hash but it is proving to be out of my skill range.

View 12 Replies View Related

Programming :: Perl One-lines Within A Ksh Script In Aix Environment Not Execute?

Jul 19, 2011

I have a script to utilize the perl one liner to replace a ip address.

Code:

#!/usr/bin/ksh
set -x
PRIP=172.15.100.176
OPRIP=172.15.100.115

[code]....

the script runs fine. but the perl one liner seems not working at all. but if i copy the perl line to a command line, it runs correctly.

View 2 Replies View Related

Programming :: Sed - Awk - Perl - Merge Lines Unless They Match A Certain String

Apr 15, 2011

What is the best way to merge lines, in sed, awk or perl, that occur between certain strings? I'm new to sed scripting and I have been working on this for some time now. I have a large file (sample below) that I need to edit.

What I need looks something like this.

I'm working with a very large file so simply merging all the lines then adding a new line character before ">contig" and after "translated" won't work, at least not with sed.

View 5 Replies View Related

Programming :: String Concatenation In Perl Result In Two Lines - Not One?

Jan 11, 2010

I am new to perl and am having trouble adding some strings together.

My full code is below:

The problem is $NewCommandB is always split into two lines, where the second line contains the "/atlas2/<blah>/<etc>/..." string. Since I am generating a .sh file to execute a lot of similar commands I need the string to all be on one line. Any idea why I get this behaviour and any suggestion on how to tell perl to make $NewCommandB a one line string?

Btw for completeness finalFileList.txt contains just file names one line after another:

View 5 Replies View Related

General :: Command Line - Print A Group Of Text Matching A Regex?

Sep 22, 2011

I'd like to print only few groups from text matching a regex. How can I do that in the Linux command line?

What other tools for text processing are there in Linux?

View 3 Replies View Related

Programming :: Randomly Selecting 160 Lines Within A Data Set Of 1000 In Perl

Apr 11, 2011

I have a dataset of around 1000 lines. Out of these 1000 lines I need to pick randomly 160 lines of data and write it to a file. The program is needed to eliminate data bias when I run the program through a reanalysis program. I am thinking I need to use the rand or srand term, but I am having difficulty writing this in perl. I have to write it in perl, because the rest of my scripts for this project are in perl, so consistency is important. The data only consists of one column of the data (YYYYMMDDHHHH).

View 2 Replies View Related

Programming :: Perl String Question:extract Lines From Somefile?

Jun 19, 2011

what's the equivalent code of Perl?sed -i 777,2545!d somefileObviously it extract lines of somefile between that 2 digits .

View 1 Replies View Related

Programming :: Perl Script Get Environment Variable LINES= For Current Session?

Apr 1, 2009

Want to return current LINES=, tryng to avoid the "hacky" backticks and string manipulation way

ie: my $somevar = `set | grep LINES`

I tried using the env command and it returns a empty value?

my $lines = $ENV{'LINES'};

$= doesnt work well for putty sessions...

my $lines = $=;

View 6 Replies View Related

Programming :: Inserting Multiple Lines - With Newline - Using Sed Or Awk

Mar 8, 2009

I need to replace part of a line in a file with multiple lines, however need to separate each line with a newline is this possible?

Example, need to remove line 2

And insert line similar to below:

If the multiple lines were part of a text file, would inserting a text file automatically include newline characters?

View 1 Replies View Related

Programming :: Matching Two Tables Of Non-matching Sizes?

Mar 2, 2011

I have two table files with x (1st column) ,y (2nd column) coordinates and intensity (3rd column). I need to match these two tables and divide the intensities at the consecutive coordinates on the 3rd column. The problem is the size of the tables are not same and I want to ignore the lines if they are not in one of the other file.

Here is Table 1:

Code:
-7.500-30.00013.006
-7.500-22.50037.952
-7.500-15.00060.962
-7.500-7.50040.922
-7.5000.00014.348
code....

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved