Tuesday, October 4, 2022

[SOLVED] Pipe commands at each xargs pass

Issue

Lets say I have this :

echo '/dev/sd'{a..d} | xargs -n 1 lsblk $1 

But now I want to pipe each pass of the xargs as for instance :

echo '/dev/sd'{a..b} | xargs -n 1 lsblk $1 | tail -n +2

Now, that does not work obviously, because the pipe is applied to the entire xargs commands. So I might try this :

echo '/dev/sd'{a..b} | xargs -n 1 bash -c "lsblk $1 | tail -n +2"

But the problem is that now $1 has no value inside of the shell.

How can I over come this? Or basically, How can I pipe the execution being done by xargs at each pass?


Solution

This should give you the report you are seeking:

find /dev/sd? -print | xargs -n 1 lsblk | egrep '^NAME|^sd'

The output on my system with only sda looks like:

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   64G  0 disk


Answered By - James Risner
Answer Checked By - David Marino (WPSolving Volunteer)