简体   繁体   中英

how to grep output from command when there is no pipeline key

I am trying to find status of firewall form Linux box via a console that does not have the pipeline symbol ( | ). how do i grep it without going through lines of output.

This is what i tried:

grep firewall < ${systemctl > outfile-firewall}
grep firewall < "$(systemctl > outfile-firewall)"

How is the first line command different from the second one? I thought you could actually run a command as a bash script using the file command with curly bracket.

grep firewall < $(systemctl)
grep firewall < "$(systemctl)"

All the outputs from commands about either give "ambiguous redirect" or "no such file or directory". I know i'm doing something wrong but it should work a good alternative to grepping output via pipeline.

You could try bash process substitution:

$ grep firewall <(systemctl)
  ufw.service                            loaded active exited    Uncomplicated firewall

Process Substitution

If you are missing the pipe symbol in your system you could put the output to a temp file and then grep it from there.

systemctl > ctl-output-file

grep firewall ctl-output-file > required-output-file

Hope that helps. Have a good day !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM