Quote:
Originally Posted by amber1
Hi,
I wrote the following script to create a report of 25 users, using sed and awk, I need to re-write some of it using perl would someone please help me.
Code:
#! /bin/bash
printf "# User: UID: GID: Owner: \n" > hwpasswd.txt
tail -n 25 /etc/passwd | sed -e 's/:x:/ /' -e 'y/:/ /' -e 's/\/bin\/bash/ /' \
| awk '{print NR ". "$1,$2,$3,$4,$5,$6,$7}' | cut -f1 -d"/" | column -t >> hwpasswd.txt
I would like to thank everyone in advance.
|
Well, what's posted above is a combination of what Habitual and mddesai gave you in your other thread. As unSpawn said, show what you've done/tried
ON YOUR OWN, and where you're stuck, and we will be happy to help.
You say you need to rewrite 'some of it'...but the whole script is only really two lines long. Or do you mean that you want to rewrite the ENTIRE thing in Perl? There are many easily-found examples of how to read a file, and read just a certain number of lines IN that file. I also suggest you look up the split command and how to use it, but that would probably be overkill for what you're looking for. Perl can do sed operations on variables at read-time, and you can even just use a system call to take your existing command and 'wrap' it.
Here's one code snippet; you should have no problems finding the rest of the hints on Google either. Please post what you come up with and where you're stuck afterwards:
Code:
use strict;
use warnings;
my $file = 'input.filename';
open my $infile, $file or die "Could not open $file: $!";
my $count = 0;
while( my $line = <$infile>) {
<put whatever operations you want here>
last if ++$count == 25;
}
close $info;