Hi,
I doubt it if the perl -ni -e 'print; print "adding value=key\n" if $.==3' myfile.txt even run from the CLI without generating a syntax error.
Simply using the below as a script
while (defined($_ = <ARGV>)) {
print $_;
print "adding value=key\n" if $. == 3;
}
could solve this easily.
Update:
I got your code wrong. You shouldn't have a syntax error using that from CLI, but as specified from the script you will.
Secondly, do you just want the line included on 3rd line or at the count of 3 lines? If the former, then the above will do, but if the later, then you might have to change this line:
print "adding value=key\n" if $. == 3;
If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author
unknown to me