dave leonard daveleonard69@yahoo.com [sed-users]
2017-07-05 13:00:18 UTC
Hello All. I have a one liner to print a word n times.
if we want to print the word hello 8 times in 8 lines, below are two methods
Method # 1 echo hello |sed 'p; x; s/^/ /; / \{8\}/d; x; s/^/\n/; D;' (by using hold space)
Method # 2 echo hello |sed ':a /\n/!s/$/\n/; P; s/$/ /; /\n \{8\}$/!ba; d;' (without using hold space)
if you like it pls add them to your list.
thanks
dave
if we want to print the word hello 8 times in 8 lines, below are two methods
Method # 1 echo hello |sed 'p; x; s/^/ /; / \{8\}/d; x; s/^/\n/; D;' (by using hold space)
Method # 2 echo hello |sed ':a /\n/!s/$/\n/; P; s/$/ /; /\n \{8\}$/!ba; d;' (without using hold space)
if you like it pls add them to your list.
thanks
dave