JanneJannesson
Technical User
Hello guys, I could really use some help. I'm trying to learn AWK but it wasn't at all as easy as I thought it would be. I have a really simple Perl script, that prints a specified text file, as well as the line number next to it. The only difference I would like to make, is that I specify the file as an argument at the command line instead of the program asking me for it. How would I go about doing this and making an AWK script? Here's my Perl script:
Sorry if I'm breaking any forum rules, this is my first post. Any advice or tips is greatly appreciated. Thanks in advance.
Code:
#!/usr/local/bin/perl
use warnings;
use strict;
print "Specify the file you want to look at:\n";
my $file_name = <STDIN>;
chomp $file_name;
open(FH, '<', $file_name) or die "Cannot open $file_name: $!";
print "This is the listed content of: $file_name\n";
my $line_n = 1;
while(<FH>){
print "$line_n. $_";
$line_n++;
}
close(FH);