Sponsored Content
Top Forums Shell Programming and Scripting How to get lines having a variable in perl? Post 302843783 by twistedpair on Thursday 15th of August 2013 04:20:39 AM
Old 08-15-2013
Thanks, i got it where i missed. I just did chomp of the variable. Now its working. I think when i extracted $ra new line character also came. So i removed it. It took almost 4 hours for to do experiments & figure out.
Code:
$ra = substr ($lastword,$n);
print "$lastword";
print "$ra";
chomp($ra);
# printing the iop corresponding to real address
open (TST, '<psi.txt');

while ( $iop = <TST>)
{ # chomp;
  if( $iop =~ /$ra/ ){
      print "$iop";
      last;
  }
}


Last edited by Franklin52; 08-15-2013 at 05:44 AM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

lines from file to variable

I have a text file that contains a word on each line. I want to be able to use each word as a variable to be put into a URL. I have been trying to put together a for loop but I am not having much luck. So basically all I am trying to do is for line in ~/desktop/test.txt do curl -s... (4 Replies)
Discussion started by: iCONAN
4 Replies

2. Shell Programming and Scripting

Multiple variable in a variable in Perl

Hi All, I am trying to convert the below Csh while loop into Perl while loop but the problem is that in this csh script, i have 2 variables inside a variable -> $count is a variable {SB$count} as a whole is another variable. Csh is able to assign values to such variable like the below but i do... (3 Replies)
Discussion started by: Raynon
3 Replies

3. Shell Programming and Scripting

[Perl] Insert lines before lines.

Hi, New problem, or challenge as they prefer in the US. I need to insert some lines in a file before certain other lines. To make it more clear: Original file: aaaa bbbbb ccccc ddddd bbbbb fffff ggggg Now I want to insert the line "NEW_NEW_NEW" when I match "fffff", but I want... (7 Replies)
Discussion started by: ejdv
7 Replies

4. Shell Programming and Scripting

combine two perl lines into a single perl command

Hi Everyone, i have a string 00:44:40 so: $tmp=~ s/://gi; $tmp=~s/({2})({2})({2})/$1*3600+$2*60+$3/e; the output is 2680. Any way to combine this two lines into a single line? Thanks (4 Replies)
Discussion started by: jimmy_y
4 Replies

5. Shell Programming and Scripting

Append variable to only certain lines

Hi There! I'm trying to write a shell script which generates a random hexadecimal number and then appends it to the end of lines XX onwards of a certain file. XX is determined by a certain string on the previous line. Thus for example, if the input file is I search for the string... (3 Replies)
Discussion started by: orno
3 Replies

6. Shell Programming and Scripting

perl - how can we name a variable base on value of another variable

Hey all, perl - how can we name a variable base on the value of another variable? for example in ksh/bash we do : export c="100" export x`echo $c`=2000 echo $x100 x100=2000 is it possible to do something similar for perl? I already tried many ways but nothing is working. I am... (3 Replies)
Discussion started by: cacm1975
3 Replies

7. Shell Programming and Scripting

Trying to break up a lines in a variable

I was trying to figure out a way to split along a CR in a variable. In the code below, the result for CPU returns CPU=`cat /proc/cpuinfo | grep -i 'model name' |awk -F ':' '{ print $2}'` for echo $CPU AMD Phenom(tm) 9850 Quad-Core Processor AMD Phenom(tm) 9850 Quad-Core Processor... (7 Replies)
Discussion started by: baggins2000
7 Replies

8. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

9. Shell Programming and Scripting

[Perl] Split lines into array - variable line items - variable no of lines.

Hi, I have the following lines that I would like to see in an array for easy comparisons and printing: Example 1: field1,field2,field3,field4,field5 value1,value2,value3,value4,value5Example 2: field1,field3,field4,field2,field5,field6,field7... (7 Replies)
Discussion started by: ejdv
7 Replies

10. Shell Programming and Scripting

Perl help - how to assign output of perl to variable

Hi, guys, i have a script i inherited from a coworker but i'm not perl savy. The script works but i would like it to work better. I want to run this command ./ciscomgrtest.pl -r "show version" -h hosts.router and have the script goto each router in the hosts.router file and run the command... (2 Replies)
Discussion started by: whipuras
2 Replies
MouseX::NativeTraits::Str(3pm)				User Contributed Perl Documentation			    MouseX::NativeTraits::Str(3pm)

NAME
MouseX::NativeTraits::Str - Helper trait for Str attributes SYNOPSIS
package MyHomePage; use Mouse; has 'text' => ( traits => ['String'], is => 'rw', isa => 'Str', default => q{}, handles => { add_text => 'append', replace_text => 'replace', }, ); my $page = MyHomePage->new(); $page->add_text("foo"); # same as $page->text($page->text . "foo"); DESCRIPTION
This module provides a simple string attribute, to which mutating string operations can be applied more easily (no need to make an lvalue attribute metaclass or use temporary variables). Additional methods are provided for completion. PROVIDED METHODS
These methods are implemented in MouseX::NativeTraits::MethodProvider::Str. It is important to note that all those methods do in place modification of the value stored in the attribute. inc Increments the value stored in this slot using the magical string autoincrement operator. Note that Perl doesn't provide analogous behavior in "--", so "dec" is not available. append($string) Append a string, like ".=". prepend($string) Prepend a string. replace($pattern, $replacement) Performs a regexp substitution ("s" in perlop). A code references will be accepted for the replacement, causing the regexp to be modified with a single "e". "/smxi" can be applied using the "qr" operator. replace($pattern, $replacement) Performs a regexp substitution ("s" in perlop) with the "g" flag. A code references will be accepted for the replacement, causing the regexp to be modified with a single "e". "/smxi" can be applied using the "qr" operator. match($pattern) Like "replace" but without the replacement. Provided mostly for completeness. chop "chop" in perlfunc chomp "chomp" in perlfunc clear Sets the string to the empty string (not the value passed to "default"). length "length" in perlfunc substr "substr" in perlfunc. We go to some lengths to match the different functionality based on "substr"'s arity. METHODS
meta method_provider_class helper_type SEE ALSO
MouseX::NativeTraits perl v5.14.2 2011-12-04 MouseX::NativeTraits::Str(3pm)
All times are GMT -4. The time now is 01:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy