Get a string from text file

  • Follow


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++;
0
Reply kris74 2/23/2005 3:02:36 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.
0
Reply Ed 2/23/2005 3:25:10 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


0
Reply Anthony 2/23/2005 3:43:32 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.
0
Reply Ed 2/23/2005 4:32:50 PM

"Ed Morton" <morton@lsupcaemnt.com> wrote in message
news:esOdnZ68GPyuLYHfRVn-jQ@comcast.com...
>
>
> 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.
>

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


0
Reply Anthony 2/23/2005 10:50:30 PM

4 Replies
116 Views

(page loaded in 0.099 seconds)

Similiar Articles:













7/10/2012 10:40:38 PM


Reply: