how to use shell's for loop to change two files
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
I would like to use for loop to create files in shell.
I have 3 files named sensor_1.nmf
, sensor_2.nmf
, sensor_3.nmf
, and I want to use a software to create another 7 python files for each files above,i.e.,
Using sensor_1
creates 7 python files like r_sensor_1.py
, r_sensor_2.py
...
My code is below:
for j in 1 2 3
do
for k in 1 2 3 4 5 6 7
nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
done
done
But it can not work. Could somebody help me? Thanks.
linux shell ubuntu python
add a comment |Â
up vote
-1
down vote
favorite
I would like to use for loop to create files in shell.
I have 3 files named sensor_1.nmf
, sensor_2.nmf
, sensor_3.nmf
, and I want to use a software to create another 7 python files for each files above,i.e.,
Using sensor_1
creates 7 python files like r_sensor_1.py
, r_sensor_2.py
...
My code is below:
for j in 1 2 3
do
for k in 1 2 3 4 5 6 7
nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
done
done
But it can not work. Could somebody help me? Thanks.
linux shell ubuntu python
1
Use bash -x to debug your code. Format your code better in your question. You are missing a do after your third line.
â Raman Sailopal
Jan 22 at 14:43
idownvotedbecau.se/itsnotworking, idownvotedbecau.se/nodebugging
â Murphy
Jan 22 at 15:22
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I would like to use for loop to create files in shell.
I have 3 files named sensor_1.nmf
, sensor_2.nmf
, sensor_3.nmf
, and I want to use a software to create another 7 python files for each files above,i.e.,
Using sensor_1
creates 7 python files like r_sensor_1.py
, r_sensor_2.py
...
My code is below:
for j in 1 2 3
do
for k in 1 2 3 4 5 6 7
nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
done
done
But it can not work. Could somebody help me? Thanks.
linux shell ubuntu python
I would like to use for loop to create files in shell.
I have 3 files named sensor_1.nmf
, sensor_2.nmf
, sensor_3.nmf
, and I want to use a software to create another 7 python files for each files above,i.e.,
Using sensor_1
creates 7 python files like r_sensor_1.py
, r_sensor_2.py
...
My code is below:
for j in 1 2 3
do
for k in 1 2 3 4 5 6 7
nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
done
done
But it can not work. Could somebody help me? Thanks.
linux shell ubuntu python
edited Jan 22 at 15:35
Murphy
1,7471517
1,7471517
asked Jan 22 at 14:25
user271856
1
1
1
Use bash -x to debug your code. Format your code better in your question. You are missing a do after your third line.
â Raman Sailopal
Jan 22 at 14:43
idownvotedbecau.se/itsnotworking, idownvotedbecau.se/nodebugging
â Murphy
Jan 22 at 15:22
add a comment |Â
1
Use bash -x to debug your code. Format your code better in your question. You are missing a do after your third line.
â Raman Sailopal
Jan 22 at 14:43
idownvotedbecau.se/itsnotworking, idownvotedbecau.se/nodebugging
â Murphy
Jan 22 at 15:22
1
1
Use bash -x to debug your code. Format your code better in your question. You are missing a do after your third line.
â Raman Sailopal
Jan 22 at 14:43
Use bash -x to debug your code. Format your code better in your question. You are missing a do after your third line.
â Raman Sailopal
Jan 22 at 14:43
idownvotedbecau.se/itsnotworking, idownvotedbecau.se/nodebugging
â Murphy
Jan 22 at 15:22
idownvotedbecau.se/itsnotworking, idownvotedbecau.se/nodebugging
â Murphy
Jan 22 at 15:22
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
0
down vote
You can use brace expansion as opposed to iterating through the for loops.
nacs2.2 -l nacs_mphs -m sensor_$1,2,3.nmf -p
r_sensor_$1,2,3,4,5,6,7.py r_sensor_$1,2,3_$1,2,3,4,5,6,7
add a comment |Â
up vote
0
down vote
At your inner for-loop you are missing the "do".
for j in 1 2 3
do
for k in 1 2 3 4 5 6 7
do
nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
done
done
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can use brace expansion as opposed to iterating through the for loops.
nacs2.2 -l nacs_mphs -m sensor_$1,2,3.nmf -p
r_sensor_$1,2,3,4,5,6,7.py r_sensor_$1,2,3_$1,2,3,4,5,6,7
add a comment |Â
up vote
0
down vote
You can use brace expansion as opposed to iterating through the for loops.
nacs2.2 -l nacs_mphs -m sensor_$1,2,3.nmf -p
r_sensor_$1,2,3,4,5,6,7.py r_sensor_$1,2,3_$1,2,3,4,5,6,7
add a comment |Â
up vote
0
down vote
up vote
0
down vote
You can use brace expansion as opposed to iterating through the for loops.
nacs2.2 -l nacs_mphs -m sensor_$1,2,3.nmf -p
r_sensor_$1,2,3,4,5,6,7.py r_sensor_$1,2,3_$1,2,3,4,5,6,7
You can use brace expansion as opposed to iterating through the for loops.
nacs2.2 -l nacs_mphs -m sensor_$1,2,3.nmf -p
r_sensor_$1,2,3,4,5,6,7.py r_sensor_$1,2,3_$1,2,3,4,5,6,7
answered Jan 22 at 14:57
Jaken551
1678
1678
add a comment |Â
add a comment |Â
up vote
0
down vote
At your inner for-loop you are missing the "do".
for j in 1 2 3
do
for k in 1 2 3 4 5 6 7
do
nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
done
done
add a comment |Â
up vote
0
down vote
At your inner for-loop you are missing the "do".
for j in 1 2 3
do
for k in 1 2 3 4 5 6 7
do
nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
done
done
add a comment |Â
up vote
0
down vote
up vote
0
down vote
At your inner for-loop you are missing the "do".
for j in 1 2 3
do
for k in 1 2 3 4 5 6 7
do
nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
done
done
At your inner for-loop you are missing the "do".
for j in 1 2 3
do
for k in 1 2 3 4 5 6 7
do
nacs2.2 -l nacs_mphs -m sensor_$j.nmf -p r_sensor_$k.py r_sensor_$j_$k
done
done
answered Jan 26 at 9:03
KarlG
113
113
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f418872%2fhow-to-use-shells-for-loop-to-change-two-files%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Use bash -x to debug your code. Format your code better in your question. You are missing a do after your third line.
â Raman Sailopal
Jan 22 at 14:43
idownvotedbecau.se/itsnotworking, idownvotedbecau.se/nodebugging
â Murphy
Jan 22 at 15:22