I am using perl -w -i~ -n inorder to filter lines from a file.
My script name is filter.pl
I use it by: filter.pl <file name>
If my file ends without newline : for example in "jjjjj"
I want to add to it a new line.
I thought to add in the END block \n to the file - The problem is that "print" prints to stdout instead of the file
and I don't have the file name (It is not in $1)
I also tried to get the file name during the loop and save it in a variable but again $1 is empty.
Please help.
Code example:
perl -w -i~ -n
BEGIN {
$filename = $1;
}
$filename = $1
s/(\S+)-@[0-9]+/$1-@<index>/g;
END{
print "\n to file";
};
My script name is filter.pl
I use it by: filter.pl <file name>
If my file ends without newline : for example in "jjjjj"
I want to add to it a new line.
I thought to add in the END block \n to the file - The problem is that "print" prints to stdout instead of the file
and I don't have the file name (It is not in $1)
I also tried to get the file name during the loop and save it in a variable but again $1 is empty.
Please help.
Code example:
perl -w -i~ -n
BEGIN {
$filename = $1;
}
$filename = $1
s/(\S+)-@[0-9]+/$1-@<index>/g;
END{
print "\n to file";
};