Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need direction inserting variables in a line

Status
Not open for further replies.
Aug 3, 2001
29
US
I have inserted text in a line with no problem
but i am lost when trying to put a variable example (A$) in a line of a file
example
perl -i.tmp -p -e 'print "$A$\n" if /THR/' $file.tmp

the line show up blank but inserted before THR
the variable is loaded right before this line of code.

any help
Thanks,


Len
 
perl -i.tmp -p -e print '$A$\n' if /THR/' $file.tmp
haunter@battlestrata.com
 
Hauter
I have tried your code exactly with the apostrophe after the /THR/ and without and I get no results
Is there any other syntax that I need to use ???

example
$ perl -i.tmp -p -e print '$var4\n' if /THR/' $file.tmp

I even tried different entries another example with results

$ perl -i.tmp -p -e print '$var4\n' if /THR/ $file.tmp
Can't open $var4\n: A file or directory in the path name does not exist.
Can't open if: A file or directory in the path name does not exist.
Can't open /THR/: A file or directory in the path name does not exist.


I am on a RS6000 Aix 4.3 system if that is of any use ??

Thanks for the response I appreciate it.

Len Turnbull
 
[tt]perl -i.tmp -p -e 'print "$A$\n" if /THR/' $file.tmp[/tt]

That's the correct way to do it, but the variable [tt]$A[/tt] won't contain any value, so it will just end up printing a blank line. In fact, the [tt]$\[/tt] will likely get replaced and you'll end up with an "n" before the line you want.

What, exactly, do you want printed before each matching line?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top