Copy the contents of all files to one file in bash in another sequence


I need to combine all the files in a folder into one file.
Files are named t1, t2, t3, ..., t1500, and the output file is " all".
I used the following command in bash: cat t* >> all
but it combines the files in sequence t1, t10, t11, ...instead of t1, t2, t3, ...
any help please.

+4
source share
4 answers

You can try

cat t{1..1500} > all

If you get any error with a command line too long, you can try

for i in {1..1500}; do
  echo "t$i"
done | xargs -n 1500 cat

A longer, but possibly more readable method that manually splits the list between several calls into cat:

{ cat t{1..100}
  cat t{101..500}    
  cat t{601..1000}
  cat t{1001..1500}
} > all
+4
source

Mine:

find -maxdepth 1 -regextype posix-egrep -regex '.*t[[:digit:]]+$' | sort -V | xargs cat > all

shopt -s extglob
printf "%s\n" t+([[:digit:]]) | sort -V | xargs cat > all

, , ( ):

printf "%s\n" t* | sort -V | xargs cat > all
+1

Try:

for i in {1..1500}; do cat t${i} >> all; done

brace-expand bash man-

0

, t1 t10 t11,

:

#!/bin/bash

for file in $(ls -1 t*)
do
  cat $file >> all
done

ls .

0
source

Source: https://habr.com/ru/post/1544042/


All Articles