LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   perl scripts (https://www.linuxquestions.org/questions/linux-newbie-8/perl-scripts-121485/)

mimf 12-01-2003 12:34 AM

perl scripts
 
Hi all,

I am trying to run a perl script that will perform the same function as the cut command. I have learned that by using 'cut -d":" f1,2,3 /etc/passwd' one can obtain the username, userid, etc from the passwd file. Can someone please help me translate this into a perl or shell script? Thanks.

guygriffiths 12-01-2003 04:44 AM

I believe the function you want is called "split". Do "man perlfunc" for more details on how to use it. If you get stuck, reply with more detail about what you want, and I'll write one for you (unless it's homework)

mimf 12-01-2003 10:08 PM

guygriffiths,

Thanks for your help. I was able to do the search for split under "man perlfunc" and got some help on split. However, i'm still stuck as my script is not printing any results. Here is the code that i have so far:

#!/usr/bin/perl

open(PASSWD, '/etc/passwd');
while (<PASSWD>) {
chomp;
($login, $passwd, $uid, $gid, $gcos, $home, $shell) = split(/:/);

and this is where i get stuck. How do i print my results?

stickman 12-01-2003 11:10 PM

You might try printing the variables that you want, for example:
print "$login $passwd\n";


All times are GMT -5. The time now is 03:50 AM.