1

I want to save some simple info of images in a directory(like the image shown below): enter image description here

But how can I write the matched parts into a file? I have tried appending >> img_info.txt but it wrote the whole output instead of being selective.

Microos
  • 1,718
  • 3
  • 16
  • 32

1 Answers1

1

Try grep's option -o as described in Can grep show only words that match search pattern?.

Cited from the other answer:

-o, --only-matching
    Print  only  the matched (non-empty) parts of a matching line,
    with each such part on a separate output line.

Aside from that grep is probably not the best tool to search and extract strings. This is rather the job of sed or awk.

Community
  • 1
  • 1
Hubert Grzeskowiak
  • 13,056
  • 5
  • 52
  • 67