Hi! I'm trying to do this:
1 -
2 -
3 -
4 -
5 -
I'm using seq for this:
seq 1 20 > filename.txt
How do I get the "-"? I've tried -f per man but can't get anything to work. Also, is there an easier or better way than using sequence? Thanks!
Hi! I'm trying to do this:
1 -
2 -
3 -
4 -
5 -
I'm using seq for this:
seq 1 20 > filename.txt
How do I get the "-"? I've tried -f per man but can't get anything to work. Also, is there an easier or better way than using sequence? Thanks!
the seq command doesn't do anything but generate sequences. How about this?
printf "%d -\n" `seq 1 20`
which amounts to printf "%d -\n" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
After much experimenting with the -f feature I finally figured out how to trick it. It needs %.0f to make it print integers, followed by whatever string you want.
seq -f '%.0f -' 1 20
I suspect it's not really meant for that and might not work the same or reliably on other systems.
Thanks everyone! Both work great and I got a lesson in -f.
------ Post updated at 05:53 PM ------
Sorry - Thanks Corona688! Didn't notice until now that both posts were from you.
If you have two constant numbers then in bash (or ksh93 or zsh) you can do
printf "%d -\n" {1..20}
Just for the fun of it - no seq
, no "brace expansion":
yes - | sed '=' | sed 'N; s/\n/ /' | head -20
1 -
2 -
3 -
.
.
.
19 -
20 -
or
yes | sed '=' | sed 'N; s/\ny/ -/' | head -20
or
yes | sed '=' | sed 'N; s/\ny/ -/; 40q'
EDIT: or - h�h�h� -
yes - | cat -n | head -n20
Not the most elegant, but for sure one of - if not "The" - most intuitive & easy to read and maintain :
seq 1 20 | sed 's/$/ -/'