Hi everyone,
I have a file input.txt which has contents like this:
1 1132 aaaa vvvv
2 1123 bbbb 222
3 1121 ssad 323
4 2222 asda 232
When i was scripting in shell i used awk to pick 2nd row 2column value i.e 1123
awk 'NR=='$2' {print $2}' input
Now i need same thing to be done using perl...please anyone can suggest how to write this is perl..
thanks in advance...:-)
Aug 6 '08
15 6315 KevinADC 4,059
Recognized Expert Specialist
No actually what i needed is script has to go 1st line 1std filed, take that value ,need to do some operations like pass that value into netsnmp command then increment by itself to 2nd line and take the value in 2nd field substitute in the netsnmp command ....please this is my main intention i thought i give example of simple file and try on my own applying it to what i want..
my input file looks like this...
11713000 1.3.6.1.4.1.253 .8.63.11.1100.1 .2 5
11610000 1.3.6.1.4.1.253 .8.63.11.1100.2 .1 5
11620000 1.3.6.1.4.1.253 .8.63.11.1100.2 .2 5
11630000 1.3.6.1.4.1.253 .8.63.11.1100.2 .3 8
OK, well, try applying what you have been shown so far to whatever it is you want to do with the file data.
OK, well, try applying what you have been shown so far to whatever it is you want to do with the file data.
Ya i tried but i am stuck up with iterating the line number please help me
KevinADC 4,059
Recognized Expert Specialist
You don't need to iterate the line numbers of you want to read all the lines. Look at the last code I posted, that reads all the lines of the file. If you ever need to get to one or some specific line, then $. (dollar-sign dot) holds that value.
You don't need to iterate the line numbers of you want to read all the lines. Look at the last code I posted, that reads all the lines of the file. If you ever need to get to one or some specific line, then $. (dollar-sign dot) holds that value.
ya i got it but $.==2 is given in your code i am trying to put it in the loop i.e value given 2 ,for next iteration it should automatically increment to 3.
for($i=0;$i<=10 ;$i++)
{
$command='perl -naF/\s+/ -e "$.=$i && print $F[4]" comms_input';
$value = `$command`;
...
...
....
}
Is there anyway to assign variable into $.
KevinADC 4,059
Recognized Expert Specialist
Look at the last code I posted, you will not see any '$.' in the code. Do you want to loop through all the lines in the file? -
open(IN,'input.txt') or die "$!";
-
while (<IN>) {
-
print +(split/\s+/)[1],"\n";
-
}
-
close IN;
-
The code you are trying to use is terrible because you are basing it from the one-liner I posted for you which is what I thought you wanted, but you don't. Another example: -
open(IN,'input.txt') or die "$!";
-
while (<IN>) {
-
my $col2 = (split/\s+/)[1];
-
do_something($col2);
-
}
-
close IN;
-
-
sub do_something {
-
my $col2 = $_[0];
-
# do something useful with $col2
-
}
-
Look at the last code I posted, you will not see any '$.' in the code. Do you want to loop through all the lines in the file? -
open(IN,'input.txt') or die "$!";
-
while (<IN>) {
-
print +(split/\s+/)[1],"\n";
-
}
-
close IN;
-
The code you are trying to use is terrible because you are basing it from the one-liner I posted for you which is what I thought you wanted, but you don't. Another example: -
open(IN,'input.txt') or die "$!";
-
while (<IN>) {
-
my $col2 = (split/\s+/)[1];
-
do_something($col2);
-
}
-
close IN;
-
-
sub do_something {
-
my $col2 = $_[0];
-
# do something useful with $col2
-
}
-
Thanks,
I tried this but i did not get what i wanted.
If my logic i requested is terrible then how it is possible to be success using awk
when i tried in awk i am getting what i wanted but i am not able to do in perl
In awk i used following code:
for((i=0;i<=5;i ++))
do
Syn=`awk 'NR=='$i' {print $6}' comms_input`
echo "$Syn"
............... ............... ...............
....<opertaions using $Syn>.....
done
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Wayne Folta |
last post by:
I've been a long-time Perl programmer, though I've not used a boatload
of packages nor much of the tacky OO.
A couple of years ago, I decided to look into Python and Ruby. Python
looked OK, but not that different. I did like the indent-as-group idea,
which was different. Ruby looked very cool. But it was impossible to
get good documentation. It seemed like a Japanese cult with a few
western initiates.
Well, MacOS X ships with Perl,...
|
by: Hunn E. Balsiche |
last post by:
in term of its OO features, syntax consistencies, ease of use, and their
development progress. I have not use python but heard about it quite often;
and ruby, is it mature enough to be use for developing serious application,
e.g web application as it has not many features in it yet.
I've given up on Perl for its ugly syntax and it is not the easiest language
to learn. How about PHP?
Thanks
|
by: Xah Lee |
last post by:
while programing in Python, one can lookup syntax or info for keywords
or modules within Python.
In the command line, type
python
to get into the python interactive program. then type
help()
>From there one can type any keyword or module name to find out the
|
by: surfunbear |
last post by:
I've read some posts on Perl versus Python and studied a bit of my
Python book.
I'm a software engineer, familiar with C++ objected oriented
development, but have been using Perl because it is great for pattern
matching, text processing, and automated testing. Our company is really
fixated on risk managnemt and the only way I can do enough testing
without working overtime (which some people have ended up doing) is by
automating my...
|
by: rbt |
last post by:
Are there any plans in the near future to support PDF files in Python as
thoroughly and completely as Perl does?
http://cpan.uwinnipeg.ca/search?query=pdf&mode=dist
I love Python's clean syntax and ease of use, etc. But on some things
(PDF for example) as barbaric as Perl's syntax is, it does outshine
Python... I hate having to use Perl just to deal with PDF files. What do
others do???
| |
by: Xah Lee |
last post by:
Sort a List
Xah Lee, 200510
In this page, we show how to sort a list in Python & Perl and also
discuss some math of sort.
To sort a list in Python, use the “sort” method. For example:
li=;
|
by: Jay |
last post by:
hi people
i am trying to connect to ppstgresql on a debian system using perl . i
am getting the following error .can any one please suggest what has to
be done
install_driver(pg) failed: Can't locate DBD/pg.pm in @INC (@INC
contains: /etc/perl /usr/local/lib/perl/5.8.3
/usr/local/share/perl/5.8.3 /usr/lib/perl5 /usr/share/perl5
/usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at
|
by: peter |
last post by:
Hi,
this is not stinky bait. If you take it that way, please dont respond..
I have been away from UNIX software for quite awhile and want to get
back into it. I liked "C" but Java seems like the way to go for
compiled langs, now days so I will learn that.
At one time, I did a bit of perl but now I see php alot. I was
wondering what you guys thinks of the pros/cons of perl and php.
|
by: KevinADC |
last post by:
Introduction
In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar methods or syntax to a less experienced perl coder. I will post links to online resources you can read if necessary. Experienced perl coders might find nothing new or useful contained in this article.
Short Review
In part one I showed you some...
|
by: masinick |
last post by:
I am aware that Perl has a lot of features that originally came from sed and awk. I have a pattern that I am using like this:
sed -n '/|Y|/p'
I want to do the same thing in Perl and be able to either save that value in some kind of variable or array or potentially write it out to a file.
For the simple case, writing out to a file, I think the syntax is very close to the sed syntax. I would like to get a few recommendations, first, on a...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |