Sponsored Content
Top Forums Shell Programming and Scripting How to get lines having a variable in perl? Post 302843689 by twistedpair on Wednesday 14th of August 2013 12:21:43 PM
Old 08-14-2013
IBM How to get lines having a variable in perl?

Hi, This might be simple question. But i couldn't find the answer.
#$ra is having a value which i have got from some other file
I want the first occurrence of the line having the value that is in variable "$ra"
This is what i have tried.
Code:
while ( $iop = <TST>)
{
  if($iop =~ /$ra/)
{
  print "$iop \n";
  last;
  }
}

plz help me.
Thanks in advance

Last edited by Scott; 08-14-2013 at 01:44 PM.. Reason: Plz 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
flockfile(3C)						   Standard C Library Functions 					     flockfile(3C)

NAME
flockfile, funlockfile, ftrylockfile - acquire and release stream lock SYNOPSIS
#include <stdio.h> void flockfile(FILE *stream); void funlockfile(FILE *stream); int ftrylockfile(FILE *stream); DESCRIPTION
The flockfile() function acquires an internal lock of a stream stream. If the lock is already acquired by another thread, the thread call- ing flockfile() is suspended until it can acquire the lock. In the case that the stream lock is available, flockfile() not only acquires the lock, but keeps track of the number of times it is being called by the current thread. This implies that the stream lock can be acquired more than once by the same thread. The funlockfile() function releases the lock being held by the current thread. In the case of recursive locking, this function must be called the same number of times flockfile() was called. After the number of funlockfile() calls is equal to the number of flockfile() calls, the stream lock is available for other threads to acquire. The ftrylockfile() function acquires an internal lock of a stream stream, only if that object is available. In essence ftrylockfile() is a non-blocking version of flockfile(). RETURN VALUES
The ftrylockfile() function returns 0 on success and non-zero to indicate a lock cannot be acquired. EXAMPLES
Example 1 A sample program of flockfile(). The following example prints everything out together, blocking other threads that might want to write to the same file between calls to fprintf(3C): FILE iop; flockfile(iop); fprintf(iop, "hello "); fprintf(iop, "world); fputc(iop, 'a'); funlockfile(iop); An unlocked interface is available in case performance is an issue. For example: flockfile(iop); while (!feof(iop)) { *c++ = getc_unlocked(iop); } funlockfile(iop); ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
Intro(3), __fsetlocking(3C), ferror(3C), fprintf(3C), getc(3C), putc(3C), stdio(3C), ungetc(3C), attributes(5), standards(5) NOTES
The interfaces on this page are as specified in IEEE Std 1003.1:2001. See standards(5). SunOS 5.11 10 Sep 2003 flockfile(3C)
All times are GMT -4. The time now is 05:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy