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,728
  • 3
  • 17
  • 34

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
  • 15,137
  • 5
  • 57
  • 74