Extract text

The problem is extract somo patterns in text file

INPUT="text (value1) text (value2) text (value3) text"

solving with:

Grep

grep -o '([^)]*)'

Vim

Capitalize the first letter of each word in a selection ?

  • \< matches the start of a word

  • . matches the first character of a word

  • \u tells Vim to uppercase the following character in the substitution string (&)

  • & means substitute whatever was matched on the left-hand side

  • g means substitute all matches, not only the first

Search and copy

in vim :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
.. |541| thumbnail:: /_static/img/fastapi/541.png
   :title: Task displayed with edit and delete options, along with an “Add New Task” button and user login info.
   :show_caption: True
   :group: fastapi

.. |965| thumbnail:: /_static/img/fastapi/965.png
   :title: Form to add a new task with optional description, date-time, and category selection.
   :show_caption: True
   :group: fastapi

Form to add a new task with optional
description, date-time, and category
selection.

.. |164| thumbnail:: /_static/img/fastapi/164.png
   :title: To-Do app dashboard with two tasks, edit/delete options
   :show_caption: True
   :group: fastapi

search for ref img |numbers| and copy in line above

g/|\d\{3\}|/t.|s/.*\(|\d\{3\}|\)$/\1/|.m-2
  • |\d\{3\}|

  • t. copy current line

  • s/.*\(|\d\{3\}|\)$/\1/ search pattern in current line

  • .m-2 move pattern above

result

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
|541|
.. |541| thumbnail:: /_static/img/fastapi/541.png
   :title: Task displayed with edit and delete options, along with an “Add New Task” button and user login info.
   :show_caption: True
   :group: fastapi


|965|
.. |965| thumbnail:: /_static/img/fastapi/965.png
   :title: Form to add a new task with optional description, date-time, and category selection.
   :show_caption: True
   :group: fastapi


|164|
.. |164| thumbnail:: /_static/img/fastapi/164.png
   :title: To-Do app dashboard with two tasks, edit/delete options
   :show_caption: True
   :group: fastapi

Note

You can do that with a :g command which marks all lines on which to act and then run a combination of a :t (copy) and :s (substitute) command.

Something like this should work:

g/2$/t.|s/2/3 This executes on each line matching 2$ the following command: :t.|s/2/3 which means, copy the current line and afterwards replace the 2 by 3 in the current (copied) line.

Move entire block to end of file

g/^..*|\d\{3\}|.*$/.,+3 m$
  • ``.,+3 `` range current , plus next 3 lines

  • m$ move to end of file

Download Images

example file
.. figure:: https://media.geeksforgeeks.org/wp-content/uploads/20250825171457206965/Output.png
   :alt: Form to add a new task with optional description, date-time, and category selection.
   :width: 964px
   :height: 1025px

 Form to add a new task with optional
 description, date-time, and category
 selection.

.. figure:: https://media.geeksforgeeks.org/wp-content/uploads/20250825171550947164/Output.png
   :alt: To-Do app dashboard with two tasks, edit/delete options
   :width: 966px
   :height: 1026px

 To-Do app dashboard with two tasks,
 edit/delete options

 **Update task** by clicking on the pencil

.. figure:: https://media.geeksforgeeks.org/wp-content/uploads/20250825171704353410/Output.png
   :alt: After clicking the edit button, a prompt appears in the To-Do app with the task input "completed," displayed over the task list and user info.
   :width: 956px
   :height: 1018px
scrape imgs urls from file
sed -n 's/\(.. figure:: \)\(.*\)/\2/p' < fastapi.rst > /tmp/imgs
download and change the name
for i in $(awk '{print $1}' /tmp/imgs) ;do wget $i -O `echo "$i" | sed -n 's/.*\([0-9][0-9][0-9]\+\).*/\1/p'`.png ; done
Output
Permissions Size User        Group       Date Modified Name
drwxr-xr-x     - ambagasdowa ambagasdowa 11 Sep 19:42   .
.rw-r--r--   43k ambagasdowa ambagasdowa 25 Aug 05:16  ├──  011.png
.rw-r--r--   40k ambagasdowa ambagasdowa 25 Aug 05:13  ├──  127.png
.rw-r--r--   57k ambagasdowa ambagasdowa 25 Aug 05:45  ├──  164.png
.rw-r--r--   34k ambagasdowa ambagasdowa 25 Aug 04:47  ├──  286.png
.rw-r--r--   39k ambagasdowa ambagasdowa 25 Aug 05:15  ├──  392.png
.rw-r--r--   56k ambagasdowa ambagasdowa 25 Aug 05:47  ├──  410.png
.rw-r--r--   40k ambagasdowa ambagasdowa 25 Aug 04:54  ├──  448.png
.rw-r--r--   48k ambagasdowa ambagasdowa 25 Aug 05:43  ├──  541.png
.rw-r--r--   48k ambagasdowa ambagasdowa 25 Aug 05:51  ├──  641.png
.rw-r--r--   16k ambagasdowa ambagasdowa 24 Aug 22:53  ├──  776.png
.rw-r--r--   55k ambagasdowa ambagasdowa 25 Aug 05:48  ├──  948.png
.rw-r--r--   45k ambagasdowa ambagasdowa 25 Aug 05:44  └──  965.png

Extract class attributes from file

sed -n 's/.*\(class=\)\("[^>]*"\)\(.*$\)/\2/p' < index.html

Details

“[^>]*”:

Swap everything between the tags and


Last update: Sep 23, 2025