[NTLUG:Discuss] Extracting a column out of input
Lance Simmons
simmons.lance at gmail.com
Mon Jan 25 19:56:51 CST 2016
I really value these kinds of threads. Even though I don't make it to
meetings, this list is very helpful!
On Mon, Jan 25, 2016 at 7:42 PM, Robert Citek <robert.citek at gmail.com> wrote:
> On Sun, Jan 24, 2016 at 7:11 PM, Leroy Tennison
> <leroy.tennison at verizon.net> wrote:
>> dpkg -l | while read col1 col2 col3; do echo $col2; done
>
> That works.
>
>> I was trying
>>
>> for i in `dpkg -l`; do read col1 col2 col3; echo col2; done
>
> The "for" construct doesn't really understand lines nor splitting the
> lines as "while" does.
>
>> while read col1 col2 col3; do echo $col2; done < ls -l
> ...
>> while read col1 col2 col3; do echo $col2; done < `ls -l`
>
> Redirecting (i.e. < or >) is used for files. To redirect the
> input/output to/from a process, use a pipe. For example:
>
> $ ls -l | while read col1 col2 col3; do echo $col2; done
>
>> What am I doing wrong and what should I do?
>
> Your first command looks good to me. I'd go with that.
>
> Regards,
> - Robert
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
--
Lance Simmons
More information about the Discuss
mailing list