LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-01-2003, 01:34 AM   #1
mimf
LQ Newbie
 
Registered: Dec 2003
Posts: 8

Rep: Reputation: 0
Unhappy 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.
 
Old 12-01-2003, 05:44 AM   #2
guygriffiths
Member
 
Registered: Jun 2003
Location: Reading, UK
Distribution: Debian 3.0, LFS
Posts: 524

Rep: Reputation: 36
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)
 
Old 12-01-2003, 11:08 PM   #3
mimf
LQ Newbie
 
Registered: Dec 2003
Posts: 8

Original Poster
Rep: Reputation: 0
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?
 
Old 12-02-2003, 12:10 AM   #4
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell and perl scripts srnerkar1 Programming 2 12-03-2005 04:07 PM
Of Perl CGI scripts and Sendmail Chrax Programming 2 06-06-2005 05:21 PM
Irssi and perl and scripts? MrDoctor Linux - Newbie 0 04-05-2004 10:44 AM
viewing perl scripts with webbrowsers. clefler Linux - Software 2 11-02-2003 02:55 PM
Combining 2 perl scripts together meluser Programming 5 03-18-2003 07:46 AM


All times are GMT -5. The time now is 06:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration