[NTLUG:Discuss] Extracting a column out of input
Pesto
dawjer at gmail.com
Mon Jan 25 19:10:14 CST 2016
Did you try dpkg -l | awk '{print $field}' ? I don't have ubuntu so I
can't test...
pesto
On Sun, Jan 24, 2016 at 9:11 PM, Leroy Tennison <leroy.tennison at verizon.net>
wrote:
> The context is I want to extract only the package name out of Ubuntu's
> 'dpkg -' where the first column is the install status, the second the
> package name and the rest a description. More generally though I want to
> know how to extract any column of data out of a multi-column list. I've
> searched the web and found one way to do it but would like to have the
> flexibility of others without having to resort to awk, perl, etc. My sense
> is that there is enough bash experience in this group that I can get an
> answer here a lot quicker than trying to find exactly what I want on the
> web. What I have so far is:
>
> dpkg -l | while read col1 col2 col3; do echo $col2; done
>
> I was trying
>
> for i in `dpkg -l`; do read col1 col2 col3; echo col2; done
>
> but read is expecting stdin. Adding 'xargs -l1' in front produced "No
> such file or directory".
>
> Then I tried
>
> while read col1 col2 col3; do echo $col2; done < ls -l
>
> to get a syntax error and
>
> while read col1 col2 col3; do echo $col2; done < `ls -l`
>
> to get "Ambiguous redirect"
>
> What am I doing wrong and what should I do?
>
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>
More information about the Discuss
mailing list