Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get pipe string length?

Tags:

string

shell

pipe

This is a code that shows my all user names.

-q user | grep -A 0 -B 2 -e uid:\ 5'[0-9][0-9]' | grep ^name | cut -d " " -f2-

For example, the output is like...

usernameone
hello
whoami

Then, I hope that I want to check a length of all user names. Like this output...

11 //usernameone
5 //hello
6 //whoami

How can I get a length of pipeline code?

like image 441
Winnie Avatar asked Apr 09 '26 15:04

Winnie


1 Answers

Given some command cmd that produces the list of users, you can do this pretty easily with xargs:

$ cat x
usernameone
hello
whoami
$ cat x | xargs -L 1 sh -c 'printf "%s //%s\n" "$(echo -n "$1" | wc -c)" "$1"' '{}'
11 //usernameone
5 //hello
6 //whoami
like image 177
Jon Gjengset Avatar answered Apr 12 '26 05:04

Jon Gjengset