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


ADVERTISEMENT

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 :: 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 :: 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 - 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 :: Bash Regex String Extraction?

Jun 10, 2011

Code:
g echo ${mm[$j]}
4 BashNotes

[code]...

View 2 Replies View Related

Programming :: Make A New Variable With The String From The Old Variable Btut Without Any Plus Sign?

Apr 7, 2010

my script has a variable which comes in the form +00.00 +0.00 -00.00 or -0.00 (the numbers can be any in that form) for any that have a + symbol I need to remove the +, but if it has a - symbol it needs to stay.

i need to make a new variable with the string from the old variable btut without any plus sign. I have tried a lot of different ways with no success, each thing I tried either left the + or removed the entire string. I think this should work but doesn't

foo=+12.40
bar=${foo#+}

View 4 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 :: 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 :: 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 :: 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 View Related

Programming :: Java Regex - Use Regular Expressions Find Out What The First Two Characters Of The String Are

Feb 2, 2011

What I am doing is reading the text from a text document and storing all of the text inside of a ArrayList. I then set one of the values of the Arraylist as a string. I want to use regular expressions find out what the first two characters of the String are. if first two characters = "//" then function(); I only care about the first two characters though. If you need any more information, just ask.

View 4 Replies View Related

Programming :: Best Way To Include Variables In String Using C

Feb 26, 2009

What's the best way to include variables in a string using C,i.e if i want to do the following query in C, how would i do that.How do i build the string variable up in C?

View 1 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 :: Grep - Include Glob With Shell Variable

Nov 10, 2010

Code:
grep -r $SEARCHDIR --include="day_$YYYY-$MM-*" -h -o -e PATTERN

The above command does exactly what I want: limit the search of files in $SEARCHDIR to those specified by --include.

I use double quotes rather than single quotes because of the shell variables. I would have thought this would cause the shell to expand the "*" but this doesn't seem to be the case.

View 1 Replies View Related

Programming :: String Match In Perl ?

Sep 15, 2010

One of my application generates a text file with an XML output in it. I need to read that log files and if the output does not match to a string in couple of tags it should create a log file with the file name and the the tag name.

The two tags where the string should match is:

Identity format tag should always be JPEG , well- formed and valid status tags should be true.

sample output file:

View 7 Replies View Related

Programming :: Change String Variable In Awk?

Nov 26, 2010

How to change string variable in awk? for example, I parse with awk script text file named some_name_with_extension.txt

I want to print only some_name in my script

Code:
....
varCompName = FILENAME
print varCompName

How to put not all symbols from FILENAME to variable?

[Code].....

View 3 Replies View Related

Programming :: Perl - Escape All Backslashes In A String Without Specify Each One ?

Sep 27, 2010

I want to read a input from user and output something like 'inputcd', which has to escape all backslashes if using double-quote. For instance, the following code would work.

Just curious if any other way I could do it without specify all backslashes? Since that takes much efforts when the sequence is long.

Code:

View 2 Replies View Related

Programming :: Changing Pattern From String In Perl

Jun 3, 2011

I am new to perl and not able to understand all the pattern matching.

I using this script to send the status to another Nagios server using ncsa. Nsca don't transmit "()" So I need to remove them before sending.

Currently I am using

Code:

for the string

Quote:

This is working fine but its is not working when there is change inside the bracket for e.g (6290)

I want to change this code to work for any change with in the brackets.

View 14 Replies View Related

Programming :: How To Append A String To A Next Line In Perl

Apr 9, 2010

I have a requirement like this..this just a sample script...

Code:

when i run this scipt...

Code:

Code:

It is appended in the same line...

I want it to be added to the next line.....

I want to do this by explitly using the filehandles in perl....and not with redirection operators in shell.

View 1 Replies View Related

Programming :: Perl - Test If String Is Uppercase

Jan 6, 2010

In my perl script I'd like to test if a string is written in uppercase letters or not. How can I do that? This type of test don't seem to work, so there must be other ways of doing this:

Code:

...return true.

I can create a subroutine that compares each character aginst a list of uppercase letters, but I'm hoping there's allready a build in routine in perl that does this...

View 14 Replies View Related

Programming :: Replace String In File Using Perl Or Sed

Jun 30, 2011

I have question about replacing a string in a file.

How can I replace the printerb's 10.1.1.1 to something else(10.1.1.2, for example) without replace printera's 10.1.1.1 accidentally?

I have tried perl -e -pi "s/10.1.1.1/10.1.1.2/g" /etc/hosts. but, perl replace both 10.1.1.1 to 10.1.1.2.

View 13 Replies View Related

Programming :: Bash Concatenating String To Variable ?

Jan 18, 2011

I have a program that loops over each word in a sentence. I need to append a constant to the beginning and end of each word. It works up until the last word on the line.

Code:

Output:

View 4 Replies View Related

Programming :: BASH - If Variable -eq String Not Working ?

Jan 24, 2010

Here is the code:

Code:

How ever when I run this script I get the following error

Quote:

I just don't get it, I have racked my brain trying to figure out every combination of how I should write this if statement and I can't get it to work.

View 2 Replies View Related

Programming :: Pass A Path As A String To A Variable?

Apr 17, 2009

I'm trying to pass a path as a string to an array, but its evaluating it as a command instead. I want to take the literal string "/mnt/accounts/user/temp/*.jpg" and assign it to an array{1}, but when i echo the array variable, it displays it as

pic1.jpg
pic2.jpg
pic3.jpg

[code]....

I just want it to be the actual text "/mnt/accounts/user/temp/*.jpg" which i will be combining with other text to create a longer path elsewhere in the code.

View 5 Replies View Related

Programming :: HOSTNAME Variable Is Being An Empty String

May 19, 2011

The script produces 2 empty lines and I don't know why.

View 1 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

Programming :: Zip A Variable With PERL Without Reading Or Writing A File?

Jun 20, 2010

There is the Archive::Zip I think I can use with Perl 5.10 but I don't know how. I don't want to read or write any files, just zip something in memory, with best compression, like

$text = "this is a test";
$zippedtext = &Zip($text);
sub Zip {

[code]...

I guess it's only a few lines.

View 3 Replies View Related

Programming :: Passing Perl Variable Into Input Tag In Cgi Script?

Aug 27, 2010

How can I to pass a perl variable into html input tag? For example, If a have got a cgi script:

Quote:

use CGI;
use DBI;
my $owner = $cgi->param('owner');

[code]....

How can I to pass $owner variable?

View 1 Replies View Related







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