Home: Perl Programming Help: Beginner:
using sed command in perl



regex2012
User

May 22, 2017, 11:11 AM


Views: 1617
using sed command in perl

I have this command
where I am trying to print the file in reverse

Code
open($FH1, "|sed '1!G;h;$!d' /tmp/inventory.txt"); 
while (<$FH1>) {
print "$_\n";
}

I am not able to get sed to print the file in reverse; I get an error.
How should I run this command within perl properly?


BillKSmith
Veteran

May 22, 2017, 1:03 PM


Views: 1612
Re: [regex2012] using sed command in perl

Your sed command is a perl double quoted string. The symbol '$' has special meaning. Your use is ambiguous. Perl does not know if you mean "${!}" (The special variable) or "\$!d" (the sed command). Use a backslash as an escape ("\$" instead of "$").

I recommend that you use a perl module rather than a shell command. Refer File::ReadBackwards
Good Luck,
Bill