PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 30, 2022

[FIXED] How to use grep output in EOF?

 October 30, 2022     eof, grep, tcsh     No comments   

Issue

I am a new leaner and I am running a program with following script:

./Multiwfn >HF-Dr.out << EOF
HF.fchk
3
21
2
2
grep 'Global surface minimum:' HF-ESP.out | awk '{print $7,$8,$9,$7,$8,$9}'
EXIT
EOF

The output of this grep is something like:

0.043532 -0.032964 1.960094 0.043532 -0.032964 1.960094

I want to use the output of grep instead of input in the script, i.e. I want the script like:

./Multiwfn >HF-Dr.out << EOF
HF.fchk
3
21
2
2
0.043532  -0.032964   1.960094  0.043532  -0.032964   1.960094
EXIT
EOF

Is there any way that I hide (make non-executable) the grep input from my program and use only its output? Thank you in advance.


Solution

I do not understand the 'make non-executable' part of your question. As I understand it, you want it executed before it is given to ./Multiwfn.

There are several solutions:

1) PesaThe's comment:

./Multiwfn >HF-Dr.out << EOF
HF.fchk
3
21
2
2
$(grep 'Global surface minimum:' HF-ESP.out | awk '{print $7,$8,$9,$7,$8,$9}')
EXIT
EOF

2) Create the input in a pipe:

(echo -e "HF.fchk\n3\n21\n2\n2;grep 'Global surface minimum:' HF-ESP.out | awk '{print $7,$8,$9,$7,$8,$9}';echo EXIT) | ./Multiwfn >HF-Dr.out

3) use an intermediate file:

cat > file <<EOF
HF.fchk
3
21
2
2
EOF
grep 'Global surface minimum:' HF-ESP.out | awk '{print $7,$8,$9,$7,$8,$9}' >> file
echo EXIT >> file
./Multiwfn < file >HF-Dr.out
rm file

I'm sure that there are more ways, but this should put you on the right track.



Answered By - Ljm Dullaart
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing