|
|
Get a string from text file
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: error for netcdf.putVar when writing data to netcdf file - comp ...... want to put in 1009 lines of strings from file date_string.txt into a netcdf file. I get the ... What you could do instead is to read your text file line-by-line with ... Shortest way to read all lines (one by one) from a text file ...Ok, I know in general a way to read text lines ony-by-one from a file into a string variable. But I miss somehow a short one-liner like: foreach... Strread String and floating point number problem! - comp.soft-sys ...Hi, I am trying to use strread, to read two columns of data in a text file. ... only the index number of the associated number, whereas I need the full string i.e ... how to extract from strings - comp.unix.programmerExtract numbers from text string - comp.lang.idl-pvwave Hi folks, Which is the ... How to Extract Strings From Bin Files | eHow.com A BIN file, or binary file, is a file ... Bash: strip file path and file extension from a file name in a ...... comp.lang.awk (sh/bash) How to check for a string ... or plain text, if ... result,string) write(*,'(a,a)') 'Brand name: ',string(5:16 ... 2) Post the bug2d.s file you get ... WRITE fails when record is greater than 255 chars - comp.os.vms ...... RELATIVE file from DCL and writing to a TEXT FILE (SEQUENTIAL). WRITE THE_FILE THE_REC The message I get it ... 255 chars - Stack Overflow Is there a way to get strings ... how to put my pdf "file" (actually a byte array) into iText PDF ...How to retrieve text content from PDF file by itext? - comp.text ... how to put my pdf ... byte array) into iText PDF ... ... to search multiple jar files for a string ... write read string data - comp.lang.java.help... file using expect.. - comp.lang.tcl ..... to grep for a particular string in a file and get ... Read data from text file; write to multiple outputs - MATLAB textread matches ... Writing non ASCII text files - comp.lang.tclI have written a tcl script that aims to write text files holding non ascii ... So writing an internally UTF-8 encoded string to a file configured for (implicit and ... Some text processing questions - comp.lang.vhdlHello all, In an effort to read and process non-trivial command files for a transactor in a testbench, I came upon a couple of questions regarding text / string ... Load Text from File to String [C#]Load Text from File to String [C#] This example shows how to load text file to string variable. StreamReader. To load text from file to string you can use StreamReader. Making a String Array from a text filei would like to put some string objects that i am reading from a text file into an object. the file has 13 lines of data and each line has 5 fields. 7/10/2012 10:40:38 PM
|
|
|
|
|
|
|
|
|