Home > Archive > AWK > February 2005 > Get a string from text file
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Get a string from text file
|
|
| Cristiano 2005-02-23, 3:55 pm |
| Hello, I'm trying to make my first AWK script and I have some
problems, when I launch this script I have some parse errors.
This is the script:
# Assegno ad un Array i nomi dei files da modificare
NomeFile[13];
NomeFile[0] = "file1.h";
NomeFile[1] = "file2.h";
NomeFile[2] = "file3.h";
NomeFile[3] = "file4.h";
NomeFile[4] = "file5.h";
NomeFile[5] = "file6.h";
NomeFile[6] = "file7.h";
NomeFile[7] = "file8.h";
NomeFile[8] = "file9.h";
NomeFile[9] = "file10.h";
NomeFile[10] = "file11.h";
NomeFile[11] = "file12.h";
NomeFile[12] = "file13.h";
i=0;
while (i<13) {
for (k=0; k<EOF; k++) {
awk -v riga='/IDL:/' -f NomeFile[i]
}
print riga;
i=i++;
| |
| Ed Morton 2005-02-23, 3:55 pm |
|
Cristiano wrote:
> Hello, I'm trying to make my first AWK script and I have some
> problems, when I launch this script I have some parse errors.
>
> This is the script:
> # Assegno ad un Array i nomi dei files da modificare
>
> NomeFile[13];
> NomeFile[0] = "file1.h";
> NomeFile[1] = "file2.h";
> NomeFile[2] = "file3.h";
> NomeFile[3] = "file4.h";
> NomeFile[4] = "file5.h";
> NomeFile[5] = "file6.h";
> NomeFile[6] = "file7.h";
> NomeFile[7] = "file8.h";
> NomeFile[8] = "file9.h";
> NomeFile[9] = "file10.h";
> NomeFile[10] = "file11.h";
> NomeFile[11] = "file12.h";
> NomeFile[12] = "file13.h";
>
> i=0;
> while (i<13) {
> for (k=0; k<EOF; k++) {
> awk -v riga='/IDL:/' -f NomeFile[i]
> }
> print riga;
> i=i++;
The above appears to be a c-shell or some other type of script
(applescript?) that attempts to call awk to search for a pattern in a
file whose name is contained in an array. The only part that's wrong
with the awk command is that you're using "-f" incorrectly. "-f" is to
provide w file that contains the awk script, not to specify the file to
act upon. So instead of this:
awk -v riga='/p/' -f file
you should be using:
awk -v riga='/IDL:/' file
If you still have problems, it's probably with your surrounding shell
(?) script and so should be addressed in the appropriate NG for that
language (e.g. comp.unix.shell if that is intended to be a shell script).
If you'd like to just have awk search in those files without a
surrounding script, all you actually need to do is this:
awk -v riga='/IDL:/' file1.h file2.h ... file13.h
Regards,
Ed.
| |
| Anthony Borla 2005-02-23, 3:55 pm |
|
"Cristiano" <kris74@gmail.com> wrote in message
news:b3562fdf.0502230702.4377f876@posting.google.com...
> Hello, I'm trying to make my first AWK script and I have some
> problems, when I launch this script I have some parse errors.
>
> This is the script:
> # Assegno ad un Array i nomi dei files da modificare
>
> NomeFile[13];
> NomeFile[0] = "file1.h";
> NomeFile[1] = "file2.h";
> NomeFile[2] = "file3.h";
> NomeFile[3] = "file4.h";
> NomeFile[4] = "file5.h";
> NomeFile[5] = "file6.h";
> NomeFile[6] = "file7.h";
> NomeFile[7] = "file8.h";
> NomeFile[8] = "file9.h";
> NomeFile[9] = "file10.h";
> NomeFile[10] = "file11.h";
> NomeFile[11] = "file12.h";
> NomeFile[12] = "file13.h";
>
> i=0;
> while (i<13) {
> for (k=0; k<EOF; k++) {
> awk -v riga='/IDL:/' -f NomeFile[i]
> }
> print riga;
> i=i++;
Not sure exactly what you attempting to do [are you calling awk from within
awk ?], but I *think* you can reduce your script down to the following:
/* FILE: test.awk */
/IDL:/ { print $0; }
and supply the file names to be processed on the command line as follows:
awk -f test.awk file*.h
This should work on both Win32 and *NIX.
I hope this helps.
Anthony Borla
| |
| Ed Morton 2005-02-23, 3:55 pm |
|
Anthony Borla wrote:
<snip>
> Not sure exactly what you attempting to do [are you calling awk from within
> awk ?], but I *think* you can reduce your script down to the following:
>
> /* FILE: test.awk */
> /IDL:/ { print $0; }
The above can be reduced to just:
/IDL:/
since printing $0 is the default action. If you did leave the "print $0"
in, you wouldn't need the terminating ";" anyway.
Ed.
| |
| Anthony Borla 2005-02-23, 8:55 pm |
| "Ed Morton" <morton@lsupcaemnt.com> wrote in message
news:esOdnZ68GPyuLYHfRVn-jQ@comcast.com...
>
>
> Anthony Borla wrote:
> <snip>
>
> The above can be reduced to just:
>
> /IDL:/
>
> since printing $0 is the default action. If you did leave the
> "print $0" in, you wouldn't need the terminating ";" anyway.
>
Thanks for that, Ed.
Default behaviours and short-cut expressions always seem to trip me up, and
I can't seem to shake that COBOL-inspired verbosity !
Anyway, nothing that a little more RTFM and command line doodling can't fix
;) !
Cheers,
Anthony Borla
|
|
|
|
|