Print certain field only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print certain field only
# 1  
Old 04-26-2011
Print certain field only

Need help. I have this:

Code:
<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.

Last edited by pludi; 04-27-2011 at 05:22 AM..
# 2  
Old 04-27-2011
here you go..
Code:
grep ayat >>>>insert file-name here<<<< | sed 's/^.*), //' | sed 's/,.*$//' | nl

cheers

Last edited by Franklin52; 04-27-2011 at 06:16 AM.. Reason: Please use code tags, thank you
This User Gave Thanks to zeroone For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print field after pattern in all lines

data: hello--hello1--hello2--#growncars#vello--hello3--hello4--jello#growncars#dello--gello--gelloA--gelloB#growncars# I want to be able to print all the values that are found between the patterns "#growncars#" and the next "#growncars#" on the same line. so the output should be: ... (8 Replies)
Discussion started by: SkySmart
8 Replies

2. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

3. UNIX for Dummies Questions & Answers

Print first field using awk

I want to print line by line only the first field from txt file input file etr,t7tu,e45xdt,e45exgt,cdgfe aqw34aw,45edgf,45estd,sert34 a232e,4etedf,w345er,qw345rw, qw354,q34asf,tw45f,q3drsf required o/p file etr aqw34aw a232e qw354 (1 Reply)
Discussion started by: stew
1 Replies

4. UNIX for Dummies Questions & Answers

Print first field in awk

Hi, I have below text file 01.02.2014,asdas,arse,aere,4tfsd 12.03.2014,sdte,45gf,8iuj,qw343w 01.02.0214,aetre,sdfgter,asfrwe I have writen below code to print only first field that is only date field from text file #!/bin/ksh echo "enter week" read week while read -r... (6 Replies)
Discussion started by: stew
6 Replies

5. UNIX for Dummies Questions & Answers

Print Nth to last field

Hey, I'm sure this is answered somewhere but my Googling has turned up nothing. I have a file with data in the following format: <desription of event> at <time and date>The desription of the event is variable length and hence when the list is displayed it is hard to easily see the date (and... (8 Replies)
Discussion started by: RECrerar
8 Replies

6. UNIX for Dummies Questions & Answers

Match pattern in a field, print pattern only instead of the entire field

Hi ! I have a tab-delimited file, file.tab: Column1 Column2 Column3 aaaaaaaaaa bbtomatoesbbbbbb cccccccccc ddddddddd eeeeappleseeeeeeeee ffffffffffffff ggggggggg hhhhhhtomatoeshhh iiiiiiiiiiiiiiii ... (18 Replies)
Discussion started by: lucasvs
18 Replies

7. UNIX for Dummies Questions & Answers

[awk] print from field n to field x

Hi, I'm trying to print every line from first field to the fourth from a file containing more. $ cat input a b c d e f g a b c d e f gI'm trying awk '{for (i=1; i <= NF-3; i++) print $i}' awkTest.datbut it printsa b c d a b c dSo, I easily guess I'm wrong. :) Of course, I want:a b... (5 Replies)
Discussion started by: daPeach
5 Replies

8. Shell Programming and Scripting

how to print field n of line m

Hi everyone, I have a basic csh/awk question. How do I print a given field from a given line in a given file? Thanks in advance! (11 Replies)
Discussion started by: Deanne
11 Replies

9. Shell Programming and Scripting

Print lines where there's no indent on the first field

Hi All, I need a code to print those lines where there's NO indents on the 1st field Example shown below. I tried to use the below codes but i am not able to see the expected result. Can any expert give any advise ? My Code cat filename| awk '$1 ~ /^+$/ {print $0}' Input 1199 ... (7 Replies)
Discussion started by: Raynon
7 Replies

10. UNIX for Dummies Questions & Answers

egrep field print

#!/bin/bash dnum=0 cd rc.d while do echo "rc$dnum.d outputs" egrep -r '^+' rc$dnum.d | sort -n +3 ((dnum++)) done WHAT I GET> rc0.d outputs rc0.d/tmpfiles:K00linuxconf rc0.d/tmpfiles:K01a1nono... (2 Replies)
Discussion started by: knc9233
2 Replies
Login or Register to Ask a Question