my working file looks like this:
<empty>
<empty>
<empty>
NAME :ABC AGE :15
GENDER :MALE
<other strings>
<other strings>
NAME
EF AGE :18
GENDER :FEMALE
<other strings>
<other strings>
NAME :GHI AGE :5
GENDER :FEMALE
<other strings>
<other strings>
output file should be:
ABC|15|MALE
DEF|18|FEMALE
GHI|5|FEMALE
i used this code:
awk -n 'data.awk > output
data.awk looks like this
{
if (substr($1,1,4) == "NAME")
{
name = substr($2,2) ; age = substr($4,2)
}
if (substr($1,1,6) == "GENDER")
{
gender = substr($2,2)
}
print name"|"age"|"gender
}
but it outputs like this:
||
||
ABC|15|MALE
ABC|15|MALE
ABC|15|MALE
ABC|15|MALE
DEF|18|FEMALE
DEF|18|FEMALE
DEF|18|FEMALE
DEF|18|FEMALE
GHI|5|FEMALE
GHI|5|FEMALE
GHI|5|FEMALE
GHI|5|FEMALE
||
||
what could be the problem?
---------- Post updated at 05:28 PM ---------- Previous update was at 05:26 PM ----------
im sorry, i forgot to disable smilies... that smiley is
---------- Post updated at 05:37 PM ---------- Previous update was at 05:28 PM ----------
is this code valid?
awk '/NAME/{print ($2,2)}||/AGE/{print ($4,2)}||/GENDER/{print ($2,2)}'input_file >>output_file
---------- Post updated at 06:38 PM ---------- Previous update was at 05:37 PM ----------
pls help me on this...
---------- Post updated at 06:38 PM ---------- Previous update was at 06:38 PM ----------
can anyone help me