Adding string from .txt file into a command â for macro
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I am processing multiple file which are saved as
N.YMDH.U.A.1.SAC
N.YMDH.U.D.2.SAC
N.YMDH.U.E.3.SAC
and so on...
I also have a .txt
file which looks as follows named YMDH_arrival_time.txt
N.YMDH.U.A.1.SAC 5.000 7.000
N.YMDH.U.D.2.SAC 7.321 4.313
N.YMDH.U.E.3.SAC 3.243 7.876
and so on ....
I want to write a script so, if the file name matches $1
, then, do a command on the file which involves the input of $2
of the same row.
What I've been attempting
#### I want the $file to be read 1 by 1 so temp_file.txt is only 1 row long then the same file is read later and the value from the .txt file can be added then the process repeated ect.
for file in /Documents/Scaling/YMDH/*.SAC do;
awk '{$1 ~ /$file/ print $1 $2 $3' /Documents/Scaling/YMDH_arrival_time.txt > temp_file.txt
#### in hope to find the row which matches and print that row into a new txt file
SAC <<EOF
r $file
CHNDHR T (I want to put the value of $2 of temp_file.txt here)
w $file.done
quit
EOF
done
any help will be appreciated or an alternate method. Thanks
awk
add a comment |Â
up vote
1
down vote
favorite
I am processing multiple file which are saved as
N.YMDH.U.A.1.SAC
N.YMDH.U.D.2.SAC
N.YMDH.U.E.3.SAC
and so on...
I also have a .txt
file which looks as follows named YMDH_arrival_time.txt
N.YMDH.U.A.1.SAC 5.000 7.000
N.YMDH.U.D.2.SAC 7.321 4.313
N.YMDH.U.E.3.SAC 3.243 7.876
and so on ....
I want to write a script so, if the file name matches $1
, then, do a command on the file which involves the input of $2
of the same row.
What I've been attempting
#### I want the $file to be read 1 by 1 so temp_file.txt is only 1 row long then the same file is read later and the value from the .txt file can be added then the process repeated ect.
for file in /Documents/Scaling/YMDH/*.SAC do;
awk '{$1 ~ /$file/ print $1 $2 $3' /Documents/Scaling/YMDH_arrival_time.txt > temp_file.txt
#### in hope to find the row which matches and print that row into a new txt file
SAC <<EOF
r $file
CHNDHR T (I want to put the value of $2 of temp_file.txt here)
w $file.done
quit
EOF
done
any help will be appreciated or an alternate method. Thanks
awk
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am processing multiple file which are saved as
N.YMDH.U.A.1.SAC
N.YMDH.U.D.2.SAC
N.YMDH.U.E.3.SAC
and so on...
I also have a .txt
file which looks as follows named YMDH_arrival_time.txt
N.YMDH.U.A.1.SAC 5.000 7.000
N.YMDH.U.D.2.SAC 7.321 4.313
N.YMDH.U.E.3.SAC 3.243 7.876
and so on ....
I want to write a script so, if the file name matches $1
, then, do a command on the file which involves the input of $2
of the same row.
What I've been attempting
#### I want the $file to be read 1 by 1 so temp_file.txt is only 1 row long then the same file is read later and the value from the .txt file can be added then the process repeated ect.
for file in /Documents/Scaling/YMDH/*.SAC do;
awk '{$1 ~ /$file/ print $1 $2 $3' /Documents/Scaling/YMDH_arrival_time.txt > temp_file.txt
#### in hope to find the row which matches and print that row into a new txt file
SAC <<EOF
r $file
CHNDHR T (I want to put the value of $2 of temp_file.txt here)
w $file.done
quit
EOF
done
any help will be appreciated or an alternate method. Thanks
awk
I am processing multiple file which are saved as
N.YMDH.U.A.1.SAC
N.YMDH.U.D.2.SAC
N.YMDH.U.E.3.SAC
and so on...
I also have a .txt
file which looks as follows named YMDH_arrival_time.txt
N.YMDH.U.A.1.SAC 5.000 7.000
N.YMDH.U.D.2.SAC 7.321 4.313
N.YMDH.U.E.3.SAC 3.243 7.876
and so on ....
I want to write a script so, if the file name matches $1
, then, do a command on the file which involves the input of $2
of the same row.
What I've been attempting
#### I want the $file to be read 1 by 1 so temp_file.txt is only 1 row long then the same file is read later and the value from the .txt file can be added then the process repeated ect.
for file in /Documents/Scaling/YMDH/*.SAC do;
awk '{$1 ~ /$file/ print $1 $2 $3' /Documents/Scaling/YMDH_arrival_time.txt > temp_file.txt
#### in hope to find the row which matches and print that row into a new txt file
SAC <<EOF
r $file
CHNDHR T (I want to put the value of $2 of temp_file.txt here)
w $file.done
quit
EOF
done
any help will be appreciated or an alternate method. Thanks
awk
edited Oct 15 '17 at 23:00
asked Oct 15 '17 at 20:55
J.DOE
62
62
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
If your YMDH_arrival_time.txt
file has fixed format <string> <number> <number>
- it's enough to use the following grep + cat approach:
grep -f <(cat /Documents/Scaling/YMDH/*.SAC) YMDH_arrival_time.txt > temp_file.txt
add a comment |Â
up vote
0
down vote
To fit your existing approach you'd just use
variable=$(cat temp_file.txt)
However check comments on RomanPerekhrest's approach.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
If your YMDH_arrival_time.txt
file has fixed format <string> <number> <number>
- it's enough to use the following grep + cat approach:
grep -f <(cat /Documents/Scaling/YMDH/*.SAC) YMDH_arrival_time.txt > temp_file.txt
add a comment |Â
up vote
2
down vote
If your YMDH_arrival_time.txt
file has fixed format <string> <number> <number>
- it's enough to use the following grep + cat approach:
grep -f <(cat /Documents/Scaling/YMDH/*.SAC) YMDH_arrival_time.txt > temp_file.txt
add a comment |Â
up vote
2
down vote
up vote
2
down vote
If your YMDH_arrival_time.txt
file has fixed format <string> <number> <number>
- it's enough to use the following grep + cat approach:
grep -f <(cat /Documents/Scaling/YMDH/*.SAC) YMDH_arrival_time.txt > temp_file.txt
If your YMDH_arrival_time.txt
file has fixed format <string> <number> <number>
- it's enough to use the following grep + cat approach:
grep -f <(cat /Documents/Scaling/YMDH/*.SAC) YMDH_arrival_time.txt > temp_file.txt
answered Oct 15 '17 at 21:10
RomanPerekhrest
22.5k12145
22.5k12145
add a comment |Â
add a comment |Â
up vote
0
down vote
To fit your existing approach you'd just use
variable=$(cat temp_file.txt)
However check comments on RomanPerekhrest's approach.
add a comment |Â
up vote
0
down vote
To fit your existing approach you'd just use
variable=$(cat temp_file.txt)
However check comments on RomanPerekhrest's approach.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
To fit your existing approach you'd just use
variable=$(cat temp_file.txt)
However check comments on RomanPerekhrest's approach.
To fit your existing approach you'd just use
variable=$(cat temp_file.txt)
However check comments on RomanPerekhrest's approach.
answered Oct 16 '17 at 1:13
jdwolf
2,392116
2,392116
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%2f398281%2fadding-string-from-txt-file-into-a-command-for-macro%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