Originally posted by RTM Must have been this:
$userinfo=`/usr/bin/grep $id /etc/passwd`;
So how do you do it in Perl ? I haven't done that much in Perl and found it rather weird that it always seemed that you had to use UNIX commands to get info - I have Perl scripts that I could have done in ksh and only kept in Perl for a bit of understanding of it.
this is how i would do it.
just so you know tho perl has a built in grep function.
you can prolly slim it down to (getpwnam("$_"))[0,2,7];
but generally:
You have a couple of ways of importing the data. (provided perl dosent have a built in function to read the file as in this example) One of the most popular is loading the data into a control structure (array/hash/combo) or working right off the file handle.
so let say you have x file and you need to work with it. you can do something like this (from the perl cookbook)
RTM did that help at all? if not toss me some stuff and i will try to explane it better. i am rather fortunet and have a variety of perl books on hand along w/ the latest cd bookself so i should be able to answer a fair amount for ya.
Last edited by Optimus_P; 04-28-2004 at 12:58 PM..
Optimus P - Cool. Thanks for the info. I think I have used something like it once, but didn't recall it. I'll try to remember for next time (actually doing any scripts has been so few and far between for the last 2 years it's hard to remember how to do much of anything any more).
Perderabo - fyi - the person was looking for a uid not account name ( see post )
Originally posted by Perderabo Same deal applies to uid. I got 3 lines with:
grep 300 /etc/passwd
but only one line with
grep '^.*:.*:300:' /etc/passwd
but in the context of your search patter the user would not be entering in the first 3 fields of the password filed they woudl only be entering in a username i believe.
no matter tho we are getting way off the topic of efficiency
Hello, there.
I'm a new beginner to Linux kernel and curious about its memory management.
When multiple applications apply for memory space at the same time, how Linux kernel solve the resource contending problem for high performance?
I have known that there is a buddy system for allocating and... (4 Replies)
I've got this program set up so that it creates files whose unique names specify the jobs their contents describe. In order to retrieve the information inside those files, I have to do a "grep" and awk or sed to extract it. I've just assumed that making a directory with that unique name that... (1 Reply)
Hello Everyone!
I am a newbie. I'd like to get key lines from a big txt file by Reg Exp, The file is nearly 22MB.
GREP or SED?which may be the best choice,more efficient way?
or any other best practise?
Thank you in advance.
Ever:) (5 Replies)
Hi !! I've finished an awk exercise. Here it is:
#!/bin/bash
function calcula
{
# Imprimimos el mayor tamaño de fichero
ls -l $1 | awk '
BEGIN {
max = $5; # Inicializamos la variable que nos guardará el máximo con el tamaño del primer archivo
}
{
if ($5 > max){ #... (8 Replies)