[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Editing a piped in stream?



On Sat 07 Jul 2018 at 12:35:02 (-0700), David Christensen wrote:
> On 07/07/18 01:51, John Crawley wrote:
> >On 2018-07-07 11:02, David Christensen wrote:
> >>On 07/06/18 09:17, Richard Owlett wrote:
> >>>Subject line is poorly phrased.
> >>>While working on a problem {solved by a different approach} I had:
> >>>    ls -l /dev/disk/by-label/ | cut -f 10,12 -d ' ' data.txt
> >>>I would then manually edit data.txt by replacing the space
> >>>character between the two fields with a tab.
> >>>I suspect I should be able to do:
> >>>    ls -l /dev/disk/by-label/ | cut -f 10,12 -d ' ' |
> >>>*something* > prettydata.txt
> >>What you want is a tool that can handle fields delimited by one
> >>or more whitespace characters.  Regular expressions come to
> >>mind, but RTFM cut(1) doesn't look promising:
> >
> >>Perhaps awk(1) or sed(1) (?).
> >
> >awk is indeed one alternative, it accepts multi-spaces between fields:
> >ls -l /dev/disk/by-label/ | awk '/total/{next};{print $9"\t"$11}'
> >> prettydata.txt
> 
> Thank you for posting an Awk solution.  Continuing my example:
> 
> 2018-07-07 12:20:30 dpchrist@po ~
> $ ls -l /bin/e* | awk '/total/{next};{print $6"\t"$7"\t"$8}'
> Feb	22	2017
> Jan	23	2017
> 
> 
> >Ideal would be a more focussed way of reading out the disk info,
> >perhaps something with blkid or lsblk?
> 
> I don't follow.  blkid(8) and lsblk(8) would be ideal for what
> purpose? Using what metric?

One might assume the OP wants something like

$ lsblk -l -o NAME,LABEL,MOUNTPOINT
NAME     LABEL       MOUNTPOINT
sda                  
sda2     SYSTEM_DRV  
sda3     LRS_ESP     
sda4                 
sda6     swan06      /
sda7     swan07      /wrenbk
sda10    swan10      [SWAP]
swanhome             /home
$ 

or whichever two columns are of interest.
(Just a selection of the output lines here.)

Cheers,
David.


Reply to: