Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

2 votes
1 answers
384 views
Using BSD jot for generating file with random content
Quote from [Using BSD jot][1] > Most every Linux system comes with GNU seq (a utility to generate > sequences of numbers or characters). However, a much older utility – > and more flexible one – is the underutilized and unknown utility, jot. > Every BSD system, including MacOS X, will come with jot...
Quote from Using BSD jot > Most every Linux system comes with GNU seq (a utility to generate > sequences of numbers or characters). However, a much older utility – > and more flexible one – is the underutilized and unknown utility, jot. > Every BSD system, including MacOS X, will come with jot (and not with > seq). (...) > In fact, to generate a large file (5Gb in this case), try this: > >
>jot -r -c -s '' $(( 1024 * 1024 * 5 )) > file.5gb
>
When I try this out it generates a 5 MB file.
-console
$ jot -r -c -s '' $(( 1024 * 1024 * 5 )) > file.5gb
$ du -sh file.5gb
5.0M    file.5gb
What does this command exactly do? How to specify size, for example 2 GB file? Is this the recommended way to generate random content files on macOS? Do you use other tools for random content files? seq can't generate random content. Is this correct?
Sybil (1983 rep)
Apr 2, 2017, 04:34 AM • Last activity: Aug 3, 2023, 10:00 AM
16 votes
5 answers
2868 views
Portable POSIX shell alternative to GNU seq(1)?
I've noticed you can't really count on `seq(1)` being available on anything but GNU systems. What's a simple reimplementation of `seq(1)` I can bring with me written in POSIX (not bash) shell? EDIT: Note that I intend to use it on at least various BSD's, Solaris, and Mac OS X.
I've noticed you can't really count on seq(1) being available on anything but GNU systems. What's a simple reimplementation of seq(1) I can bring with me written in POSIX (not bash) shell? EDIT: Note that I intend to use it on at least various BSD's, Solaris, and Mac OS X.
Elizafox (816 rep)
Jul 25, 2016, 05:23 PM • Last activity: Jul 14, 2023, 09:02 PM
54 votes
8 answers
47689 views
How to display numbers in reverse order using seq(1)?
I have iterate over numbers in various order. I am able to display them in increasing order, even with steps like: $ seq --separator="," 1 10 1,2,3,4,5,6,7,8,9,10 $ seq --separator="," 1 2 10 1,3,5,7,9 I am also able to display them in reverse order, neither continuous nor step wise. $ seq --separat...
I have iterate over numbers in various order. I am able to display them in increasing order, even with steps like: $ seq --separator="," 1 10 1,2,3,4,5,6,7,8,9,10 $ seq --separator="," 1 2 10 1,3,5,7,9 I am also able to display them in reverse order, neither continuous nor step wise. $ seq --separator="," 10 1 $ seq --separator="," 10 2 1 No output for above commands. My shell details: $ bash --version GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2005 Free Software Foundation, Inc. Let me know how I would be able to display the numbers in descending order?
mtk (28478 rep)
Feb 15, 2013, 09:47 AM • Last activity: Dec 2, 2022, 12:54 PM
1 votes
2 answers
4414 views
how to use seq with xargs to curl request
I'm working on `curl` commmand that performs an action based upon parms value curl 'http://www.example.com/actionid?id=123' `id` value i want to pump dynamically so `seq 1 10 | xargs -I + curl 'http://example.com/actionid?id=123'` In output I'm getting curl 'http://example.com/actionid?id=+' curl 'h...
I'm working on curl commmand that performs an action based upon parms value curl 'http://www.example.com/actionid?id=123 ' id value i want to pump dynamically so seq 1 10 | xargs -I + curl 'http://example.com/actionid?id=123 ' In output I'm getting curl 'http://example.com/actionid?id=+ ' curl 'http://example.com/actionid?id=+ ' curl 'http://example.com/actionid?id=+ ' .... how can I pass it as value I also tried seq 1 10 | xargs -I + curl 'http://example.com/actionid?id=123 '`< <(printf '+\n' $(seq 1 10) I'm getting the same results. **solution** placed ' around -I '~' and its working now.
user316389 (29 rep)
Oct 13, 2020, 09:01 PM • Last activity: Nov 10, 2022, 04:31 PM
1 votes
1 answers
120 views
sed with seq command problem
With this bash script ```bash seq=$(seq 3) sed -i "i ${seq}" input.txt ``` I get: ``` sed: -e expression #1, char 6: unknown command: ` ' ``` But the following script works. ```bash sed -i "i 1 2 3" input.txt ``` Why?
With this bash script
seq=$(seq 3)
sed -i "i ${seq}" input.txt
I get:
sed: -e expression #1, char 6: unknown command: `
'
But the following script works.
sed -i "i 1 2 3" input.txt
Why?
Tokubara (113 rep)
Jul 3, 2022, 08:41 AM • Last activity: Jul 3, 2022, 08:51 AM
2 votes
4 answers
1778 views
I need to create a loop in bash to join images vertically and ouput multiple joined Pages for print
**I am running Ubuntu 18.04.** I have a directory full of storyboard images in `.jpg` format as below. image-0000.jpg image-0001.jpg image-0002.jpg image-0003.jpg image-0004.jpg . . image-3898.jpg image-3899.jpg **Merging 13 images vertically gives me a Single page.** So I think I need to use below...
**I am running Ubuntu 18.04.** I have a directory full of storyboard images in .jpg format as below. image-0000.jpg image-0001.jpg image-0002.jpg image-0003.jpg image-0004.jpg . . image-3898.jpg image-3899.jpg **Merging 13 images vertically gives me a Single page.** So I think I need to use below command, using a range of 13 numbers at a time in a loop and save to a directory "./Merged". convert -append image-{range of 13}.jpg ./Merged/page_001.jpg > **My experiment and thought process is as below.** I am trying to use a nested for loop and seq -w as below. But I am unable understand, how to loop the scrip in such a way that it takes first 13 files (from image-0000 to image-0012), merges them and saves in the ./Merged/ folder. Then come out of the loop and again take the next 13 files (from image-0013 to image-0025) and so on. Till all .jpg files in the current folder are finished or till 300 pages are generated. **My Script** #!/bin/bash # As 3899 image slices will be converted to 300 pages # I thought to run for loop 300 times for ((page=1; page<=300; page++)) do # As images are slices of pages. for slices in $(seq -w 0 3899) do # We need to merge 13 times so... # Should i use for loop with increment as below? # for ((smerge=1; smerge<=13; smerge++)) # do # convert "SOME LOGIC" ./Merged/page_001.jpg # done # **OR** # somehow take 13 numbers from sequence convert image-$slices_{RANGE}.jpg -append ./Merged/page_$page.jpg done done
user3025253 (23 rep)
Jun 12, 2018, 10:49 PM • Last activity: Apr 30, 2022, 08:00 PM
1 votes
1 answers
330 views
Why when using seq -s delimiter is after the last element?
I was trying different examples from Unix shell tutorial with `seq` command and got a different result in my terminal. command: ``` seq -s '/' 1 5 ``` result: ``` 1/2/3/4/5/ ``` instead of ``` 1/2/3/4/5 ``` The command works as expected in online `bash`, only mine does it in a different way.
I was trying different examples from Unix shell tutorial with seq command and got a different result in my terminal. command:
seq -s '/' 1 5
result:
1/2/3/4/5/
instead of
1/2/3/4/5
The command works as expected in online bash, only mine does it in a different way.
MTabaka (11 rep)
Dec 22, 2021, 10:05 PM • Last activity: Dec 22, 2021, 11:06 PM
-3 votes
1 answers
672 views
2 decimal increment in seq makes everything with 2 decimal
I want to use this command in bash: datarange=$(seq 0.5 0.25 5.5) with output echo $datarange = 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75 4.00 4.25 4.50 4.75 5.00 5.25 5.50 The problem is that this is for going into directories labeled D$i in a for loop where $datarange i...
I want to use this command in bash: datarange=$(seq 0.5 0.25 5.5) with output echo $datarange = 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75 4.00 4.25 4.50 4.75 5.00 5.25 5.50 The problem is that this is for going into directories labeled D$i in a for loop where $datarange is called, but also where it's going to be for a qsub file it calls certain files numbered after a python numpy arange like this one: >>> import numpy as np >>> Steps=np.arange(0.5,5.75,0.25) >>> print(Steps) [0.5 0.75 1. 1.25 1.5 1.75 2. 2.25 2.5 2.75 3. 3.25 3.5 3.75 4. 4.25 4.5 4.75 5. 5.25 5.5 ] As the name needs a str I write this in Python filenamelist=[filenamer+str(Steps[j])+'.fdf' for j in range(len(Steps))] resulting in a file name like this one for example in the 2nd element (in python counting, whereas it's the 3rd one): filenamer1.0.fdf whereas for the 3rd (4th) would be: filenamer1.5.fdf and the next one: filenamer1.75.fdf As I need the D$i to be the same of the NumPy arange data, how can make that possible? If I use seq -f %.3g, it only keeps me the three more significant decimals but without adding a decimal. If I use seq -f %.3f, it would be the same result that if I won't use anything at all. May I need to stick to Python to change the directory and call over the program or is it solvable in Bash? EDIT: to clarify, i need help to do it in Bash And I dont want to elliminate all trailing zeros using %g because for example as you see in Python arange 1. and such stay in the strings as 1.0 and such, and so i can't read the files properly.
PARCB (1 rep)
Mar 24, 2021, 09:46 PM • Last activity: Mar 25, 2021, 02:35 PM
2 votes
1 answers
133 views
Using "seq", If one column is equal to 5, continue the other column
For example, I want to start from the far right column, and once that reaches 5, continue the count from the second farthest column. ``` 0.0.0.0 0.0.0.1 0.0.0.2 0.0.0.3 0.0.0.4 0.0.0.5 0.0.1.5 0.0.2.5 0.0.3.5 0.0.4.5 0.0.5.5 0.1.5.5 0.2.5.5 0.3.5.5 0.4.5.5 0.5.5.5 1.5.5.5 2.5.5.5 3.5.5.5 4.5.5.5 5.5...
For example, I want to start from the far right column, and once that reaches 5, continue the count from the second farthest column.
0.0.0.0
0.0.0.1
0.0.0.2
0.0.0.3
0.0.0.4
0.0.0.5
0.0.1.5
0.0.2.5
0.0.3.5
0.0.4.5
0.0.5.5
0.1.5.5
0.2.5.5
0.3.5.5
0.4.5.5
0.5.5.5
1.5.5.5
2.5.5.5
3.5.5.5
4.5.5.5
5.5.5.5
So far, I was thinking of using: for i in $(seq 0 5); do echo "0.0.0.$i"; done and once i == 5, then well set i=0, and move the echo to the third position.
curiousJoe (57 rep)
Dec 4, 2020, 08:09 AM • Last activity: Dec 5, 2020, 07:55 AM
5 votes
2 answers
563 views
`seq` and bash brace expansion failing
IINM my system is failing when _`bash`ing_ for i in {0..10000000}; # Seven zeroes. do false; done # `bash` exited and its `tmux` pane/window was closed. or for i in $(seq 0 10000000); # Seven zeroes. do false; done # `bash` exited and its `tmux` pane/window was closed. but not when for i in {0..1000...
IINM my system is failing when _bashing_ for i in {0..10000000}; # Seven zeroes. do false; done # bash exited and its tmux pane/window was closed. or for i in $(seq 0 10000000); # Seven zeroes. do false; done # bash exited and its tmux pane/window was closed. but not when for i in {0..1000000}; # Six zeroes. do false; done # Finished correctly. Can you please briefly explain the internals of this behavior and prompt a workaround for getting the task done?
41754 (95 rep)
Aug 27, 2014, 12:24 PM • Last activity: Nov 2, 2020, 05:09 AM
1 votes
1 answers
1009 views
How do I iterate through multiple bash arrays and elements that are not previously stored as variables?
## Problem I'm trying to Solve The problem I am trying to solve is being able to iterate through elements in two bash arrays as well as individual elements such that these elements are not stored previously as variables; they are declared on the spot: ``` for e in "$(seq -f "number-%g" 0 4) $(seq -f...
## Problem I'm trying to Solve The problem I am trying to solve is being able to iterate through elements in two bash arrays as well as individual elements such that these elements are not stored previously as variables; they are declared on the spot:
for e in "$(seq -f "number-%g" 0 4) $(seq -f "number-%g" 5 9) number-10" ; do echo $e; done
When I execute this, I see:
$ for e in "$(seq -f "number-%g" 0 4) $(seq -f "number-%g" 5 9) number-10" ; do echo $e; done
number-0 number-1 number-2 number-3 number-4 number-5 number-6 number-7 number-8 number-9 number-10
it seems as is everything is printing out on the same line. ## Resources I've consulted I've read and experimented with resources on these pages: * https://www.thegeekstuff.com/2010/06/bash-array-tutorial/ (Specifically the section: "13. Concatenation of two Bash Arrays") * https://linuxhint.com/bash_range/ ## Experiments I've tried ### Experiment 1 This stores the arrays in intermediate variables:
seq1="$(seq -f "number-%g" 0 4)"
seq2="$(seq -f "number-%g" 5 9)"
elem="number-10"
all=("${seq1[@]}" "${seq2[@]}" "${elem}")
Printing this out yields:
$ for e in $all; do echo $e; done
number-0
number-1
number-2
number-3
number-4
which seems to not pick up the second array or the last element. ### Experiment 2 Here I explicitly store two arrays instead of generating them with seq, however, I 1.) do not want to store intermediate variables for this question as per "problem I am trying to solve", and 2.) I want to use the seq command as opposed to stating the arrays explicitly.
$ seq1=("number-0" "number-1" "number-2" "number-3" "number-4")
$ seq2=("number-5" "number-6" "number-7" "number-8" "number-9")
$ all=("${seq1[@]}" "${seq2[@]}" "number-10")
Printing this out along with "number-10" yields:
$ for e in "${all[@]}"; do echo $e; done
number-0
number-1
number-2
number-3
number-4
number-5
number-6
number-7
number-8
number-9
number-10
I look forward to hearing some bash tricks! Thanks!
jamescranston (113 rep)
Jul 23, 2020, 05:45 PM • Last activity: Jul 23, 2020, 06:58 PM
2 votes
2 answers
484 views
multiple sequences in a single variable
I have two type ranges which I need to get it in a single variable. How can I do that? eg: I have one range like bs0401 to bs0405 (bs0401,bs0402,bs0403...) and another range like bn0201 to bn0205(bn0201,bn0202,bn0203..) and I need both these expansion under one variable. I can do for single sequence...
I have two type ranges which I need to get it in a single variable. How can I do that? eg: I have one range like bs0401 to bs0405 (bs0401,bs0402,bs0403...) and another range like bn0201 to bn0205(bn0201,bn0202,bn0203..) and I need both these expansion under one variable. I can do for single sequence like h=$(seq -f "bs%02g" 0401 1 0405) but not sure how can Include multiple sequence assigned in a single variable so that echo $h will given like bs0401 bs0402 bs0403 bs0404 bs0405 bn0201 bn0202 bn0203 bn0204 bn0205
ARthur (37 rep)
Jun 21, 2020, 04:00 PM • Last activity: Jun 22, 2020, 08:23 AM
1 votes
3 answers
48 views
Monitor how far the SEQuence has got
I have the following script which has been running for over 3 days: seq -w 1 1000000 | while read i; do (./myscript.pl $i >> output.txt); done Is it possible to find out how far it has got with the sequence?
I have the following script which has been running for over 3 days: seq -w 1 1000000 | while read i; do (./myscript.pl $i >> output.txt); done Is it possible to find out how far it has got with the sequence?
oshirowanen (2661 rep)
Jun 11, 2020, 07:50 PM • Last activity: Jun 16, 2020, 08:40 PM
1 votes
6 answers
1123 views
Faster way to enumerate number than GNU seq?
I want to enumerate numbers (between 1 to 10 136 range) but so far, most tools and trick I tried would struggle after 10 9 numbers or so... Here some examples (with smaller range): For `seq 99999` ``` real 0m0.056s user 0m0.004s sys 0m0.051s ``` For `seq 9999999` ``` real 1m5.550s user 0m0.156s sys...
I want to enumerate numbers (between 1 to 10136 range) but so far, most tools and trick I tried would struggle after 109 numbers or so... Here some examples (with smaller range): For seq 99999
real    0m0.056s
user    0m0.004s
sys     0m0.051s
For seq 9999999
real    1m5.550s
user    0m0.156s
sys     0m6.615s
So on so forth... Thing is, it start to struggle only after the 9th number or so (in this case, 999999999) and on ward. I thought of splitting them in smaller range and running them in parallel: ` cat 10), it still struggle and seems like it would take forever to complete... I don't need to write the enumerated numbers to a file, but i do need it to be on stdout, so that i can process it. EDIT: @Isaac mentioned in his answer (and in the comment) something that *could* work, and while it does goes through 1010 much faster than anything else mentioned, it still struggle for any range bigger than 1010 (and by extension, 10136). Worth mentioning since it was mentioned as a possible duplicate to this post (which it technically isn't). How do i enumerate from 0 to 10136 faster than GNU seq does?
Nordine Lotfi (2472 rep)
Jun 15, 2020, 12:21 AM • Last activity: Jun 16, 2020, 01:38 AM
2 votes
2 answers
4713 views
Execute as fast as possible many curl commands
I am gathering some data locally at home on a Raspberry Pi and I want to send the data as fast as possible to a REST API (which I own) on a server on the web. The locally gathered data could flow as fast as 100 records per second. If I execute a curl command in a loop it will send the data... Wait f...
I am gathering some data locally at home on a Raspberry Pi and I want to send the data as fast as possible to a REST API (which I own) on a server on the web. The locally gathered data could flow as fast as 100 records per second. If I execute a curl command in a loop it will send the data... Wait for the 200 response then process the next record... Much slower than my internal data flow. I have found some hints here on Stackoverflow and tried to adapt them but it wouldn't send the curl commands in parallel. I know my code is not the prettiest (particularly about the usage of the mycurl function ) and I am ready for suggestions #!/bin/bash host="localhost" port="********" mycurl() { data="field1=${1}&field2=${2}&field3=${3}&field4=${4}&field5=${5}&field6=${6}&field7=${7}&field8=${8}&field9=${9}&field10=${10}" curl --output /dev/null -d $data --silent -X POST https://myapi/myendpoint ; } export -f mycurl #----------------------LOOP starts------------------------ while true; do nc -d $host $port | while IFS="," read -r f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22 do if [ "$f15" != "" ]; then seq 1000 | parallel --no-notice --joblog log -j0 mycurl ::: ${f5} ::: ${f7} ::: ${f8} ::: ${f15} ::: ${f16} ::: ${17} ::: ${18} ::: ${19} ::: ${20} ::: ${21}; fi done done
Pierre H. (41 rep)
Aug 26, 2018, 08:21 AM • Last activity: May 17, 2020, 12:02 PM
0 votes
1 answers
121 views
Write all numbers between 0 and large number (both inclusive) to a file in random order
For simulation I am trying to do, I want a text file with numbers ranging from 0 to 2^33 which is a huge number. I have used this command: ``` seq 0 Number >> OUTPUT FILE ``` But this is very slow. The file is nearly 94 GB, so we can't use `shuf`.Then I have used [terashuf](https://github.com/alexan...
For simulation I am trying to do, I want a text file with numbers ranging from 0 to 2^33 which is a huge number. I have used this command:
seq 0 Number >> OUTPUT FILE
But this is very slow. The file is nearly 94 GB, so we can't use shuf.Then I have used [terashuf](https://github.com/alexandres/terashuf) by Alexandres which is also taking quite a lot of time. Even though I have done what I wanted to do, I wanted to know if there is a faster way to do this in a single command and whether there is any way in which we can truly randomize the order of these numbers **NOTE:** Even though I have been using Linux from quite a log time, I have very limited knowledge on bash scripting. So please try to give answers which a beginner can understand.
Uday (101 rep)
May 2, 2020, 01:26 PM • Last activity: May 2, 2020, 01:48 PM
3 votes
1 answers
259 views
Search directories containing numbers larger than a certain threshold in their name
This is the command that I have and would like to modify with an additional condition: find /home/user/backups/ -mindepth 2 -maxdepth 3 -name "*~EEEE000.tif" -print This is the output of `ls /home/user/backups/`: backup20170101_somerandomstring backup20170115_somerandomstring backup20170230_somerand...
This is the command that I have and would like to modify with an additional condition: find /home/user/backups/ -mindepth 2 -maxdepth 3 -name "*~EEEE000.tif" -print This is the output of ls /home/user/backups/: backup20170101_somerandomstring backup20170115_somerandomstring backup20170230_somerandomstring backup20170305_somerandomstring backup20170408_somerandomstring backup20170521_somerandomstring . . . backup20190111_somerandomstring backup20190130_somerandomstring backup20190209_somerandomstring backup20190301_somerandomstring backup20190303_somerandomstring backup20190311_somerandomstring backup20190313_somerandomstring backup20190412_somerandomstring . . . backup20200102_somerandomstring backup20200103_somerandomstring backup20200105_somerandomstring backup20200110_somerandomstring . . . I only want to search directories that were generated after 2019-03-10. So this can be easily thought of as **directories** **which in their name have numbers larger than 20190310 right after the word backup**. I can thin of seq but do not know how to use it alongside find. And I am sure there are better options out there. seq -f "backup%1.0f" 20190310 20200131
paropunam (267 rep)
Jan 30, 2020, 10:17 AM • Last activity: Jan 30, 2020, 11:19 AM
-2 votes
3 answers
886 views
how to create 2 columns with repeated sequence of values in linux?
I want to create a 2 columns like: 1 10 1 20 1 30 1 40 1 50 2 10 2 20 2 30 2 40 2 50 3 10 3 20 3 30 3 40 3 50 any suggestion please?
I want to create a 2 columns like: 1 10 1 20 1 30 1 40 1 50 2 10 2 20 2 30 2 40 2 50 3 10 3 20 3 30 3 40 3 50 any suggestion please?
zara (1333 rep)
Aug 18, 2016, 07:00 PM • Last activity: Dec 20, 2019, 09:24 PM
-1 votes
2 answers
100 views
Creating a sequence with _ in the number
Hey I feel like I am probably being a little stupid but I cannot seem to find anywhere how to utilize a sequence with symbol in it. I want to be able to run a sequence from two date and times: `20191110_2330` and `20191111_0200` but I cannot work out how to read over the `_`. Any advice would be gre...
Hey I feel like I am probably being a little stupid but I cannot seem to find anywhere how to utilize a sequence with symbol in it. I want to be able to run a sequence from two date and times: 20191110_2330 and 20191111_0200 but I cannot work out how to read over the _. Any advice would be greatly appreciated.
Sulli (1 rep)
Nov 10, 2019, 10:28 PM • Last activity: Nov 12, 2019, 01:00 AM
4 votes
4 answers
1786 views
Is there an alphabetic equivalent of nl or seq?
I have a file where I'd like to number the lines using "the alphabet" (simple ascii a, b, c, etc.) instead of numbers. So where I could do: nl somefile I'd like to do something like: abc somefile and get output like: ``` a line 1 of file b line 2 of file c line 3 of file ... ``` Even an alphabetic e...
I have a file where I'd like to number the lines using "the alphabet" (simple ascii a, b, c, etc.) instead of numbers. So where I could do: nl somefile I'd like to do something like: abc somefile and get output like:
a line 1 of file
b line 2 of file
c line 3 of file
...
Even an alphabetic equivalent of seq could help -- I could use paste to prefix lines. To keep things simple, my file would have 26 or less lines (so abc would not need to wrap letters like ...x, y, z, aa, ab, ac... kind of thing.)
Mike (153 rep)
Jun 15, 2019, 12:42 PM • Last activity: Jun 16, 2019, 01:55 PM
Showing page 1 of 20 total questions