Print certain field only

Need help. I have this:

<li><a href="/wiki/Yunus_(sura)" title="Yunus (sura)">Yunus</a> (<a href="/wiki/Islamic_view_of_Jonah" title="Islamic view of Jonah" class="
mw-redirect">Junus</a> or <a href="/wiki/Jonah">Jonah</a>), 109 ayat, 11 ruku's, Meccan</li>
<li><a href="/wiki/Hud_(sura)" title="Hud (sura)">Hud</a> (<a href="/wiki/Hud_(prophet)" title="Hud (prophet)">Hud</a>, sometimes thought to
 be <a href="/wiki/Eber">Eber</a>), 123 ayat, 10 ruku's, Meccan</li>
<li><a href="/wiki/Yusuf_(sura)" title="Yusuf (sura)">Yusuf</a> (<a href="/wiki/Islamic_view_of_Joseph" title="Islamic view of Joseph">Youse
f</a> or <a href="/wiki/Joseph_(son_of_Jacob)" title="Joseph (son of Jacob)">Joseph</a>), 111 ayat, 12 ruku's, Meccan</li>
<li><a href="/wiki/Ar-Ra%27d">Ar-Ra'd</a> (The Thunder), 43 ayat, 6 ruku's, Medinan</li>
<li><a href="/wiki/Ibrahim_(sura)" title="Ibrahim (sura)">Ibrahim</a> (<a href="/wiki/Islamic_view_of_Abraham" title="Islamic view of Abraha
m" class="mw-redirect">Ibr�hīm</a> or <a href="/wiki/Abraham">Abraham</a>), 52 ayat, 7 ruku's, Meccan</li>
<li><a href="/wiki/Al-Hijr">Al-Hijr</a> (The Rocky Tract, <a href="/wiki/Mada%27in_Saleh" title="Mada'in Saleh">Al-Hijr</a>, The Stoneland,
The Rock City), 99 ayat, 6 ruku's, Meccan</li>
<li><a href="/wiki/An-Nahl">An-Nahl</a> (The Honey Bees), 128 ayat, 16 ruku's, Meccan</li>
<li><a href="/wiki/Al-Isra">Al-Isra</a> (<a href="/wiki/Isra_and_Mi%27raj" title="Isra and Mi'raj">Isra</a>, The Night Journey or The <a hre
f="/wiki/Israelites" title="Israelites">Children of Israel</a>), 111 ayat, 12 ruku's, Meccan</li>
<li><a href="/wiki/Al-Kahf">Al-Kahf</a> (The Cave), 110 ayat, 12 ruku's Meccan</li>
<li><a href="/wiki/Maryam_(sura)" title="Maryam (sura)">Maryam</a> (<a href="/wiki/Islamic_views_on_Mary" title="Islamic views on Mary" clas
s="mw-redirect">Maryam</a> or <a href="/wiki/Mary_(mother_of_Jesus)" title="Mary (mother of Jesus)">Mary</a>), 98 ayat,6 ruku's, Meccan</li>
<li><a href="/wiki/Ta-Ha">Ta-Ha</a> (Ta-Ha), 135 ayat, 8 ruku's, Meccan</li>
<li><a href="/wiki/Al-Anbiya">Al-Anbiya</a> (The <a href="/wiki/Prophets_of_Islam" title="Prophets of Islam">Prophets</a>), 112 ayat, 7 ruku
's, Meccan</li>
<li><a href="/wiki/Al-Hajj">Al-Hajj</a> (The Pilgrimage, The <a href="/wiki/Hajj">Hajj</a>), 78 ayat, 10 ruku's, Medinan</li>
<li><a href="/wiki/Al-Mu%E2%80%99minoon">Al-Mu�minoon</a> (The Believers), 118 ayat, 6 ruku's, Meccan</li>

I want my output to be like this:

  1. 109 ayat
  2. 123 ayat
  3. 111 ayat
    .
    .
    .
    an so on...

that is, for each line of the input, I want the output to have

  1. a number by placing the number in the first field. Notice above the input does not have a line number.
  2. second field has the number and word "ayat" based on the input

I can not use print $n because the field number of "n ayat" is not consistent. I was thinking if awk (or any other command) see word "ayat" it will print the field before it but I do not know how to do this. Please help. Thanks.

here you go..

grep ayat >>>>insert file-name here<<<< | sed 's/^.*), //' | sed 's/,.*$//' | nl

cheers

1 Like