bash - How to get the length of each word in a column without AWK, sed or a loop? -
this question has answer here:
- length of string in bash 8 answers
is possible? have one-liner count number of words in file. if output have looks this:
3 abcdef 3 abcd 3 fec 2 abc
this done in 1 line without loops , thinking if add column length of each word in column. thinking use wc -m
count characters, don't know if can without loop?
as seen in title, no awk, sed, perl.. old bash.
what want:
3 abcdef 6 3 abcd 4 3 fec 3 2 abc 3
where last column length of each word.
while read -r num word; printf '%s %s %s\n' "$num" "$word" "${#word}" done < file
Comments
Post a Comment