[NTLUG:Discuss] sed awk question
Jim Wildman
jim at rossberry.com
Mon Aug 12 11:12:56 CDT 2002
awk is very nice for column oriented work. Perl (of course) includes
the capability as well. My rule is that if there needs to be a lot of
interaction with the script or between the script and the OS, use perl.
Otherwise use awk (particularly for commandline scripts, etc).
In your case, sort will do the whole thing
-u will return only unique lines
--key=1,5 would use the first 5 characters to sort with
-n forces the sort key to be interpreted as a number
The default key is the whole line.
The catch is that it will only work on fixed format strings
sort -u --key=4,10 file1 > file2
or something like that.
If you have variable size fields, then you are going to need to use awk
or perl to deal with it.
------------------------------------------------------------------------
Jim Wildman, CISSP jim at rossberry.com
http://www.rossberry.com
On Mon, 12 Aug 2002, Bobby Wrenn wrote:
> My reading led me to believe that awk was best for working with fields rather
> than whole lines.
>
> My question last week made me think perl was better than either and more
> versatile than either.
>
> So, here is my question this week. I need to sort a comma delimited file and
> return only those line where the first field is unique. Currently I am
> pulling the file into Access and elimating duplicates there. There has to be
> a better way.
>
> TIA
> Bobby
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>
More information about the Discuss
mailing list