Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-01-2003, 12:34 AM   #1
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, 04:44 AM   #2
Registered: Jun 2003
Location: Reading, UK
Distribution: Debian 3.0, LFS
Posts: 524

Rep: Reputation: 37
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, 10:08 PM   #3
LQ Newbie
Registered: Dec 2003
Posts: 8

Original Poster
Rep: Reputation: 0

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:


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

and this is where i get stuck. How do i print my results?
Old 12-01-2003, 11:10 PM   #4
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";


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 03:07 PM
Of Perl CGI scripts and Sendmail Chrax Programming 2 06-06-2005 04:21 PM
Irssi and perl and scripts? MrDoctor Linux - Newbie 0 04-05-2004 09:44 AM
viewing perl scripts with webbrowsers. clefler Linux - Software 2 11-02-2003 01:55 PM
Combining 2 perl scripts together meluser Programming 5 03-18-2003 06:46 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:47 PM.

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