grep on specific line of the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep on specific line of the file
# 1  
Old 05-28-2008
grep on specific line of the file

Hi,

how can we search for a word (with case ignore )on specific line numbers

ex:

Awk /^regEX/ with condition on first line or second line

Awk/^ regex1/ on line 1

Awk /^regEX2/ on line 3


thanks in advance

Last edited by rider29; 05-28-2008 at 04:43 PM..
# 2  
Old 05-28-2008
For the second line:

Code:
/^regEX/ && NR==2

Regards
# 3  
Old 05-28-2008
thank you, here how can we search with ignore case using awk' /^test/' ?
# 4  
Old 05-28-2008
Hammer & Screwdriver another approach, albeit a bit different

To find out about a particular line, say the 4th line of xx lines:

Code:
cat myfile | head -4 | tail -1 | grep -i "test"

OK, not very elegant, but a way to return info about a specific line of text in a file. Smilie
# 5  
Old 05-29-2008
Quote:
Originally Posted by rider29
thank you, here how can we search with ignore case using awk' /^test/' ?
Code:
 awk 'toupper($0) ~ /^TEST/{do your suff here..}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep string in a file and paste next line in a specific way

Hello, I know there are many questions and replies regarding grep command. What I would like to do is a bit different. File A: hello world welcome to my page this is my test site how are you I am fine, thank you where have you been I was in hospital really hope you are fine now Thanks,... (10 Replies)
Discussion started by: baris35
10 Replies

2. Shell Programming and Scripting

Grep pattern after specific line number in a file

Hi guys, I am running a while loop in a script ro read a file line by line. Now I want to run a grep only on the lines below the line I am that is being read by the while loop. Eg: If my while loop is on line 4 of the file, the grep only runs below line 4 and does not include line 1,2... (3 Replies)
Discussion started by: Junaid Subhani
3 Replies

3. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

4. Shell Programming and Scripting

How to grep an empty line in a specific column of a file?

Suppose i have the following data : cat file.txt 12431,123334,55353,546646,14342234,4646,35234 123123,3535,123434,132535,1234134,13535,123534 123213,545465,23434,45646,2342345,4656,31243 2355425,2134324,53425,342,35235,23434,234535 3423424,234234,65465,,2344,35436,234524,234... (7 Replies)
Discussion started by: Ravi Tej
7 Replies

5. Shell Programming and Scripting

fetch last line no form file which is match with specific pattern by grep command

Hi i have a file which have a pattern like this Nov 10 session closed Nov 10 Nov 9 08:14:27 EST5EDT 2010 on tty . Nov 10 Oct 19 02:14:21 EST5EDT 2010 on pts/tk . Nov 10 afrtetryytr Nov 10 session closed Nov 10 Nov 10 03:21:04 EST5EDT 2010 Dec 8 Nov 10 05:03:02 EST5EDT 2010 ... (13 Replies)
Discussion started by: Himanshu_soni
13 Replies

6. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

7. Shell Programming and Scripting

grep a specific line from a file

Is there a way to grep only one line from a file listing name of files? If I use head -1 it's ok(the first line only) If I use head -2 it's not good because I have already checked the first line. I'd like something like this: while test $i -le $max do grep "$3" `head -$i temp.txt` >... (4 Replies)
Discussion started by: Max89
4 Replies

8. UNIX Desktop Questions & Answers

grep lines with two specific characters somewhere in the line

I'm having trouble with extracting certain lines from a file based on whether they have all the required fields. Original file: snt:594:Sam N This bpt:2342:Bob P That lr:123 wrp:23:Whoever Person cor:794 Desired output: snt:594:Sam N This bpt:2342:Bob P That wrp:23:Whoever Person ... (3 Replies)
Discussion started by: Chthonic
3 Replies

9. Shell Programming and Scripting

grep specific line

if i have a file that contains common directory -bash-3.2$ cat test /opt /opt/mdm /opt/test -bash-3.2$ how can i grep "/opt" so that the result should only show "/opt" (6 Replies)
Discussion started by: ryandegreat25
6 Replies

10. Shell Programming and Scripting

grep a word from a specific line

for example: searches only for single word for single word this is line three match=$(grep -n -e "single" data.txt) this command will stored "..... single ...... single" into search. how can i grep the single word just from line 2 only?? (3 Replies)
Discussion started by: blurboy
3 Replies
Login or Register to Ask a Question