[linux-help] Re: Awk & Sed
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Nathan wrote:
>
> I'm looking for anyone comfortable with Awk & Sed (or
> maybe Perl) who would be willing to help me with the
> combined projects of learning these languages, and
> making a script to parse tab delimited files for my
> job.
Just a sample:
awk -F' ' '{
printf("Row %d\n", NR)
for (i=1;i<=NF;i++) {
printf(" Field %d: %s\n", i, $i)
}
}' tab-delimited-file
If you're running bash, you'll probably have to use ^v to
quote the TAB character (-F argument).
NR is the number of records processed to date, starting
from 1. NF is the number of fields in the current record.
RS separates records (default newline; i.e., one record
per line). FS separates fields (default space, which is
one or more consecutive isspace() characters). You can
change FS with the -F command line option, or you can
put it into a BEGIN block:
BEGIN { FS = "\t" }
Which saves you from having to use a literal TAB.
Fields are numbered from 1 .. NF inclusive; $1 gives you
the first field, $2 the second, etc.; a variable after
the $ is evaluated: e.g., $NF always gives you the last
field.
> It's got to run on WinDOS. (I've already found
> versions of Awk & Sed that are made for DOS. I've
> also found a version of Perl for DOS.)
You'll also need a shell to pipeline between sed and awk:
they're two separate programs, frequently piped together.
> I'd like to learn to use Awk & Sed so I can say
> goodbye to my crappy Microsoft macros which aren't
> event compatible between two sequential versions of
> Word. I've thought of using Perl (not that I've
> totally decided against it), but I'd like to minimize
> the amount of stuff I have to put on each computer to
> make the script work. Would any of you be willing to help?
I can help with awk and sed, but if you're running on DOS,
you might be better off with Perl, which is more powerful,
which usually eliminates the need for a separate shell, or
whole environment like cygwin.
> Nate
--
/*
* Tom Hull * thull at kscable.com * http://www.ocston.org/~thull/
*/
-- This is the linux-help@xxxxxxxxx list. To unsubscribe,
visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi
|
|