Search code examples
linuxcommandarp

I'm trying to use grep command


I'm new to Linux so it may sound silly.

I'm trying to execute a command

sudo arp-scan -l | grep DEVICEMACADDRESS
  1. where does the output of this command gets saved. ? ?
  2. How I can append time once the given mac address is found. ? ?

Thank you.


Solution

  • Ad 1: Grep by default prints output to STDOUT (standart output), which is, in your case, terminal.

    If you want to save the output to the file, use output redirection:

    some command > file #this will write file anew (any file will be overwritten)
    another command >> file #this will append to file, (file will be created, if doesn't exist)
    

    If you want to save the output to variable, use following syntax:

    NAMEOFVARINUPPERCASE=$(whole command)
    

    Please note there are NO spaces around =. Also note, that this variable is available only to current terminal session. However, you can always export it, or save it to file.

    Ad 2:

    Use following syntax:

    (command_to_find_mac && echo $(date)) >> file