Newbie shell question.
Posted in 2000
Topics: Migration, Import/Export & Data Conversion
To all, How do you print a record from a unload file only if the 5th field has a value? I'm looking in a Korn shell book and can't seem to fine the example I need. TIA Cheryl
In article <881ecv$27$1@news.xmission.com>,
"Kemp, Cheryl" <CKemp@cvty.com> wrote:
>
> To all,
> How do you print a record from a unload file only if the 5th field
> has a value? I'm looking in a Korn shell book and can't seem to fine
> the example I need.
>
> TIA
> Cheryl
Cheryl,
this is something I do all the time. I use one-liner awk script. (I
suspect Clay will beat me to the puch with a more elegant perl
script. ;-)
OK, suppose the unload file is named yutz.unl:
$ awk -F'|' 'length($5) > 0 {print}' yutz.unl
Mind the single quotes. The -F'|' tells awk to use the | character as
the field separator instead of blank. You need to quote it lest the
shell interpret it as a pipe command. (You can probably use a "quote"
here as well.) The next string in the single quotes as the entire awk
script, which will print the input line only if the fifth field has
data.
HTH.
-- jake
+----- Jacob Salomon - DBA JSalomon@bn.com - --------------------------+
|------------------- Bulletin Board Announcement ----------------------|
| Congregants will please note that the bowl at the back of the church |
| bearing the sign "For the Sick" is for monetary contributions only. |
+----------------------------------------------------------------------+
Sent via Deja.com http://www.deja.com/
Before you buy.