RE: ** OT : awk works only for first line
Date: Wed, 28 Jan 2009 10:46:14 -0700
Message-ID: <C7F02F80BA89DB47AA7345919AF9F72C9DD36E_at_bcxoemb02.dpsg.net>
The issue is the 'for' statement which breaks a string by white space.
Please try the following -
$
$ cat emp_lis.ksh
cat emp_1 | while read f1
do
emp_name=`echo $f1 |awk -f emp.awk`
echo $emp_name
done
$ ksh emp_lis.ksh
john_ray
joe_smith
bill_bates
jane_de
$
From: oracle-l-bounce_at_freelists.org
[mailto:oracle-l-bounce_at_freelists.org] On Behalf Of A Joshi
Sent: Tuesday, January 27, 2009 8:49 PM
To: oracle-l_at_freelists.org; Mark.Bobak_at_proquest.com
Subject: RE: ** OT : awk works only for first line
Mark,
Here is the full code and full file :
$cat emp_lis.sh
emp_sal=`cat emp_1`
for f1 in $emp_sal
do
emp_name=`echo $f1 |awk -f emp.awk`
echo $emp_name
done
$cat emp.awk
BEGIN {
FS=":"
}
{print $1}
$cat emp_1
john_ray:8743943
joe_smith: 2134093
bill_bates: 3243243
jane_de: 9843243
$. ./emp_lis.sh
john_ray
joe_smith
2134093
bill_bates
3243243
jane_de
9843243
$
- On Tue, 1/27/09, Bobak, Mark <Mark.Bobak_at_proquest.com> wrote:
From: Bobak, Mark <Mark.Bobak_at_proquest.com> Subject: RE: ** OT : awk works only for first line To: "ajoshi977_at_yahoo.com" <ajoshi977_at_yahoo.com>, "oracle-l_at_freelists.org" <oracle-l_at_freelists.org> Date: Tuesday, January 27, 2009, 8:15 PM
Can you show a small sample of your data, one line that works correctly, and one
or more that don't work correctly?
-Mark
From: oracle-l-bounce_at_freelists.org [oracle-l-bounce_at_freelists.org] On Behalf
Of A Joshi [ajoshi977_at_yahoo.com]
Sent: Tuesday, January 27, 2009 7:25 PM
To: oracle-l_at_freelists.org
Subject: ** OT : awk works only for first line
Hi,
I am trying awk to get the first word from each line in a file : I am doing :
BEGIN { FS=":"
}
{print $1}
For the first line : it prints the first work. For other lines it prints other
words also. I tried to put in FS as space but that did not help. Can someone
help? I did try google but could only find example like above. Thanks for help.
-- http://www.freelists.org/webpage/oracle-l Please be conscious of the environment and print this email only if absolutely necessary. This e-mail (including any attachments) is confidential and may contain privileged information of Dr Pepper Snapple Group, Inc. and/or its subsidiaries ("Dr Pepper Snapple Group"). If you are not the intended recipient or receive it in error, you may not use, distribute, disclose or copy any of the information contained within it and it may be unlawful to do so. If you are not the intended recipient, please notify us immediately by returning this e-mail to us at mailto:mailerror_at_dpsg.com and destroy all copies. Any views expressed by individuals within this e-mail do not necessarily reflect the views of Dr Pepper Snapple Group. This e-mail does not constitute a binding offer, acceptance, amendment, waiver or other agreement, unless the intent that an e-mail will constitute such is clearly stated in the body of the email. Recipients are advised to subject this e-mail and attachments to their own virus checking, in keeping with good computing practice. Please note that e-mail received by Dr Pepper Snapple Group may be monitored in accordance with applicable law. -- http://www.freelists.org/webpage/oracle-lReceived on Wed Jan 28 2009 - 11:46:14 CST