Hi,
I can see a close file command in awk but I can't open it again.
Actually I want to take user input in gawk script which can't get
command line input as it automatically calls gawk when executed. The
command line input goes to gawk instead of my script and gawk tries to
open whatever is written at command prompt. Is there a way to make
getline read from stdin instead of the filename given at command
prompt and then open that file afterwards?
Thanks,
Asra
|
|
0
|
|
|
|
Reply
|
asra_baig
|
10/11/2003 1:27:54 AM |
|
On 10 Oct 2003 18:27:54 -0700, asra_baig@rocketmail.com (Asra) wrote:
>Hi,
>I can see a close file command in awk but I can't open it again.
>Actually I want to take user input in gawk script which can't get
>command line input as it automatically calls gawk when executed. The
>command line input goes to gawk instead of my script and gawk tries to
>open whatever is written at command prompt. Is there a way to make
>getline read from stdin instead of the filename given at command
>prompt and then open that file afterwards?
>Thanks,
Something like this:
BEGIN{
while( ( getline < "/dev/stdin" ) > 0 ) {
work on STDIN here
}
}
{
work on file here
}
The question doesn't agree with the subject, so to read STDIN during
the file:
{
condition test that activates STDIN {
while( ( getline < "/dev/stdin" ) > 0 ) {
work on STDIN here
}
}
else {
code to work on file
}
}
T.E.D. (tdavis@gearbox.maem.umr.edu - e-mail must contain "T.E.D." or my .sig in the body)
|
|
0
|
|
|
|
Reply
|
Ted
|
10/11/2003 2:26:03 AM
|
|
In article <bc519543.0310101727.5a0c93b7@posting.google.com>,
Asra <asra_baig@rocketmail.com> wrote:
% command line input as it automatically calls gawk when executed. The
% command line input goes to gawk instead of my script and gawk tries to
% open whatever is written at command prompt.
To come at your question from a different angle, it's possible to
pre-process the command line and strip out the bits that aren't
files. The simplest way is to have the calling script assign
variables, in the form
awk 'script' var="value" var2="value2" files
or
awk -v var="value" -v var2="value2" 'script' files
Apart from that, the command-line can be manipulated in a BEGIN block.
It's tokenised and stuck into an array called ARGV[], and it is this
array that's used to determine what files to process in the
pattern/action part of the script.
BEGIN {
var = ARGV[1]
ARGV[1] = ""
var2 = ARGV[2]
ARGV[2] = ""
}
run as
awk 'script' "value" "value2" files
, the program will assign var and var2 appropriately, then start
processing the necessary files.
--
Patrick TJ McPhee
East York Canada
ptjm@interlog.com
|
|
0
|
|
|
|
Reply
|
ptjm
|
10/11/2003 7:15:20 PM
|
|
On 10 Oct 2003 18:27:54 -0700, Asra
<asra_baig@rocketmail.com> wrote:
> Hi,
> I can see a close file command in awk but I can't open it again.
> Actually I want to take user input in gawk script which can't get
> command line input as it automatically calls gawk when executed. The
> command line input goes to gawk instead of my script and gawk tries to
> open whatever is written at command prompt. Is there a way to make
> getline read from stdin instead of the filename given at command
> prompt and then open that file afterwards?
> Thanks,
> Asra
Use "-".
--
Cheops' Law:
Nothing ever gets built on schedule or within budget.
|
|
0
|
|
|
|
Reply
|
Bill
|
10/14/2003 5:27:33 AM
|
|
|
3 Replies
199 Views
(page loaded in 0.067 seconds)
Similiar Articles: comp.lang.awk - page 11Gawk to take user input when a file is already given 3 54 (10/11/2003 1:27:54 AM) Hi, I can see a close file command in awk but I can't open it again. GAWK: A fix for "missing file is a fatal error" - comp.lang.awk ...In one of my scripts, I found that in GAWK, if a file is ... By the way, my input file specification is: /proc ... that this has a problem in the case where the user ... Eval in gawk - comp.lang.awk-- To reply by e-mail, please remove the extra dot in the given address ... program for evaluation "new program" file input. ... one of my scripts, I found that in GAWK, if a file ... Removing duplicates from within sections of a file - comp.lang.awk ...... representing the current # input record is NOT already ... The PDF file of the whole gawk user guide is at http://www.gnu ... So, given SECTION a b c c SECTION c d e a ... bigger memory allocation for Gawk - comp.lang.awk... gsub(/\\\n/," ");gsub(/\n^ /," ")}1' large= file >largefile2 gawk ... trying to do, with a brief example of input and ... avoiding last line") Oh, yes, I thought I already ... delete columns csv file - comp.lang.awk... received the following error: gawk: file ... of the so-called tutorial; I'd already discarded it and started to read the gnu guide to gawk. ... If the same filename is given twice ... efficiency in awk - comp.lang.awk... Doesn't handle nulls in the input ... First, you can't use any gawk options as options to your program (and if the user ... file, the name of the file must be given as the ... GNU-awk bug in sub()/gsub() - comp.lang.awkINPUT: x EXPECTED OUTPUT: \ ACTUAL OUTPUT: \\ also ... Well, in this case it is somewhat understandable, given ... you count extracting info from a leafnode .overview file ... processing output of external command - comp.lang.awk... file: exclude list # second file: main input ... for which the sub-groups already exist ... main batch file contains: call export-domino-groups.cmd gawk -f test.awk domino ... AWK question - split string into variables - comp.unix.shell ...Hi, I'm writing a script (ksh) where the user enters ... At least 2 fields must be given hour:minute, if 3 fields ... do the test with GNU awks' "mktime()" function: gawk ... TCL(Tool Command Language) Scripting :: How to remove a single ...If the user has given input as 123096, The script should remove the ... processing is probably already so slow ... depends on both the encoding of input file The GAWK Manual - Reading Input Files - Utah :: School of ComputingThen the input file is read, and the second rule in the ... record currently being processed (and records already ... Given the input line, John Q. Smith, 29 Oak St., Walamazoo ... 7/17/2012 4:03:37 AM
|