Mailinglist Archive: opensuse (3166 mails)

< Previous Next >
re: [SLE] Record grep

awk is a general purpose program for doing all sorts of reporting.

It is a little slow, but highly functional.

It is great for scanning logs/formatted text files.

I have written several "hundred line" awk scripts.

For what you describe try:
awk -F: '/root/ { print }' /etc/passwd

If you want specific fields try:
awk -F: '/root/ { print "user = " $1, ", uid = " $3, ", shell = ", $7}' /etc/passwd

If you want the pattern to be in a specific field, not just anywhere on the line try:
awk -F: '$3 == 0 { print }' /etc/passwd

The one thing I have never tried is a multi-char separator.

Even if it is not explicitly supported, a short awk script could pull in the whole line and scan for the separator string.


>> Hi everybody!

>> Does anyone know of an existing command-line utility that will look
>> through a simple database file (with records separated by some ascii
>> character, or series of characters) for a pattern, then print the
>> entire record to the screen when a record containing a match is found?

>> I've written a little utility in C which does this, and I've been thinking
>> about adding some additional features before offering it to the community.

>> I won't bother if I'm reinventing the wheel however, so if anyone knows if
>> such a thing exists already, please let me know.

>> --
>> JVOLLMER@xxxxxxxx

>> --
>> Check the headers for your unsubscription address
>> For additional commands send e-mail to suse-linux-e-help@xxxxxxxx
>> Also check the archives at
>> Please read the FAQs: suse-linux-e-faq@xxxxxxxx

< Previous Next >