Last updated on November 17th, 2015 at 06:04 am
This tutorial will show you how to split /etc/passwd file using perl script.If you just have look at the passwd file you can see the lines are separated with semicolon “:” and that is being used to split the file here.
#!/usr/bin/perl $filename = '/etc/passwd'; open(FILE, $filename) or die "Could not read from $filename, program halting."; print "USERNAME USERID\n"; print "---------------------------------------\n"; while(<file>) { chomp; @fields = split(':', $_); print "$fields[0] $fields[2]\n"; close FILE;