|
Home > Archive > Unix questions > August 2006 > AWK question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| pawan_test 2006-08-09, 7:22 pm |
| Hi All,
I have a question,
I have a data coming through like this;
Problem='A' , 'B' , 'C' , 'D' , 'F' , 'G' , 'H' , 'I' , 'J' , 'K' , 'L'
When I use awk like this;
echo $Problem |awk -F, '{print $1}'
I see only 'A' on the command line.
I am trying to put the variable Problem in a loop so that I can print
one by one like this ;
'A',
'B',
'C',
'D',
....
'L'
Can anyone please give me suggestion.
Thanks
| |
| Ed Morton 2006-08-10, 1:33 am |
| pawan_test wrote:
> Hi All,
>
> I have a question,
>
> I have a data coming through like this;
>
> Problem='A' , 'B' , 'C' , 'D' , 'F' , 'G' , 'H' , 'I' , 'J' , 'K' , 'L'
>
Let's assume you don't really have those white spaces or the assignment
will fail. So you really have this:
Problem='A','B','C','D','F','G','H','I',
'J','K','L'
> When I use awk like this;
>
> echo $Problem |awk -F, '{print $1}'
> I see only 'A' on the command line.
Take it one step at a time. Gievn the result of echo $problem:
$ echo $Problem
A,B,C,D,F,G,H,I,J,K,L
then of course awk will print A. Right?
>
> I am trying to put the variable Problem in a loop so that I can print
> one by one like this ;
> 'A',
> 'B',
> 'C',
> 'D',
> ...
> 'L'
Oh, then what you intended to do preceeding the awk call was this:
$ Problem=" 'A','B','C','D','F','G','H','I','J','K',
'L'"
$ echo "$Problem"
'A','B','C','D','F','G','H','I','J','K',
'L'
> Can anyone please give me suggestion.
You could do this:
$ echo "$Problem" | awk -F, '{for (i=1;i<=NF;i++) print $i}'
'A'
'B'
'C'
'D'
'F'
'G'
'H'
'I'
'J'
'K'
'L'
or this:
$ echo "$Problem" | awk -F'\n' -v RS=',' '{print $1}'
'A'
'B'
'C'
'D'
'F'
'G'
'H'
'I'
'J'
'K'
'L'
but the simplest for just printing one per line is probably just to use tr:
$ echo "$Problem" | tr ',' '
'
'A'
'B'
'C'
'D'
'F'
'G'
'H'
'I'
'J'
'K'
'L'
Regards,
Ed.
|
|
|
|
|