bash - Concatenate all files except one calling system - Python -


to concatenate txt files of folder, can done cat easily:

cat ./tmp*.txt >./tmp/all.txt 

however, want concatenate files except 1 can done following command explained here:

cat ./tmp/!(1.txt) >./tmp/all_except_1.txt 

these commands work on command line, trying call them python os.system command , gives error

>>> import os >>> os.system('cat ./tmp/!(1.txt) >./tmp/all_except_1.txt') sh: 1: syntax error: "(" unexpected 

does know why , how can solved?

you need enable extended pattern matching in bash before call it:

os.system("bash -o extglob -c 'cat ./tmp/!(1.txt) >./tmp/all_except_1.txt'") 

Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -