[buug] parsing a file

Jon McClintock jammer at weak.org
Fri Dec 21 15:00:12 PST 2001


On Fri, Dec 21, 2001 at 02:38:14PM -0800, johnd wrote:
> Any suggestions?
> 
> I have a transaction file...plain text. 
> 
> the first two lines I want excluded from the parsing (they are not
> transactions)
> 
> I need to know about each line where the 6th field is '0' and the delimiter
> is ':'
> 
> 
> the first two lines don't have any delimiter characters, so if it would simplify
> things just to say parse lines that are delimitted, that would be ok. (cut
> has a flag for that)

Well, if the 7th (I think you meant 7th) field is always the last field, then 
why not use grep?

darkhawk:~/> grep ':0$' foo
1000:john d:12/21/01:40.23:mem:cat:0
2000:sadie:12/21/01:23.00:dog food:pet:0

That is, if you want the whole line; the grep output can always be piped into
awk to pull out specific columns. You can also search on other columns:

grep ':string:[^:]*$'   # The second to last column
grep '^string:'         # The first column
grep '^[^:]*:string:'   # The second column

man 1 grep for more information.

-Jon




More information about the buug mailing list