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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file availability getline way

Status
Not open for further replies.

visitnag

Programmer
Sep 21, 2006
15
IN
Hi,

I am using getline to check whether input file is available or not.

The following is working fine:

Input file name: file<ym>

read -p "Enter month : " ym
awk 'BEGIN{
print getline < "file'$ym'" <0 ? "Not Available" : "Available"​
}'

but when i use the variable within awk its not working

awk 'BEGIN{
month=202303
print getline < "file"month <0 ? "Not Available" : "Available"​
}'

Please help
Thank you








 
Hi

Dumb thing as according to operator precedence should be fine, but in reality you have to add [highlight]parentheses[/highlight] :
Code:
awk '[b]BEGIN[/b][teal]{[/teal]
[navy]month[/navy][teal]=[/teal][purple]202303[/purple]
[b]print getline[/b] [teal]<[/teal] [highlight]([/highlight][i][green]"file"[/green][/i][navy]month[/navy][highlight])[/highlight] [teal]<[/teal][purple]0[/purple] [teal]?[/teal] [i][green]"Not Available"[/green][/i] [teal]:[/teal] [i][green]"Available"[/green][/i]
[teal]}[/teal]'


Feherke.
feherke.github.io
 
Thank you very much!
Does this parenthesis syntax apply only when getline is used?
 
Hi

Maybe my memories are failing, as I can not reproduce it right now, but I have a feeling that also met it with [tt]print[/tt] when writing to file. But I would say on file/pipe input/output operations.


Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top