Home > Back-end >  Extract a specific output from a command and save it in a file
Extract a specific output from a command and save it in a file

Time:03-15

I'm using a command that outputs this :

Api key for 'Bouncer':
    6d718520343907968ca8e47d2e4c9046
Please keep this key since you will not be able to retrieve it

I want to extract this part 6d718520343907968ca8e47d2e4c9046 and save it in a file key.txt

What is the cleanest way to do this ??

CodePudding user response:

awk 'NR==2{print $1}' file.txt

or

grep 6d file.txt | xargs

CodePudding user response:

With GNU grep. If the searched string always have 32 characters:

grep -Eo '[^ ]{32}' file

Output:

6d718520343907968ca8e47d2e4c9046
  •  Tags:  
  • bash
  • Related