interesting grep behaviour


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting interesting grep behaviour
# 1  
Old 06-18-2011
interesting grep behaviour

I suppose that this is not actually a script question, but I noticed this while working on a bash script homework assignment and I have been impressed with the quality of posts here -- so that is why I posted it here.

I have this text file named textfile:
Code:
total 40
-rwxr-xr-x 1 joeblow users 356 Jun 14 13:28 count.ok
-rwxr-xr-x 1 joeblow users 411 Jun 14 13:30 count.s
-rwxr-xr-x 1 joeblow users 344 Jun 14 12:50 count.shhht
-rwxr-xr-x 1 joeblow users 168 Jun 13 11:55 example.s
-rwxr-xr-x 1 joeblow users 71 Jun 13 19:37 example2.s
-rwxr-xr-x 1 joeblow users 262 Jun 12 20:21 findtext.s
-rwxr-xr-x 1 joeblow users 203 Jun 12 11:58 findtext.txt
-rwxr-xr-x 1 joeblow users 547 Jun 13 11:59 right.s
-rwxr-xr-x 1 joeblow users 286 Jun 12 20:12 showargs.s
-rwxr-xr-x 1 joeblow users 197 Jun 12 11:58 showargs.txt
-rw-r--r-- 1 joeblow users 0 Jun 14 16:32 textfile

I do a "grep -n .s textfile"
Code:
$ grep -n .s textfile
2:-rwxr-xr-x 1 joeblow users 356 Jun 14 13:28 count.ok
3:-rwxr-xr-x 1 joeblow users 411 Jun 14 13:30 count.s
4:-rwxr-xr-x 1 joeblow users 344 Jun 14 12:50 count.shhht
5:-rwxr-xr-x 1 joeblow users 168 Jun 13 11:55 example.s
6:-rwxr-xr-x 1 joeblow users 71 Jun 13 19:37 example2.s
7:-rwxr-xr-x 1 joeblow users 262 Jun 12 20:21 findtext.s
8:-rwxr-xr-x 1 joeblow users 203 Jun 12 11:58 findtext.txt
9:-rwxr-xr-x 1 joeblow users 547 Jun 13 11:59 right.s
10:-rwxr-xr-x 1 joeblow users 286 Jun 12 20:12 showargs.s
11:-rwxr-xr-x 1 joeblow users 197 Jun 12 11:58 showargs.txt
12:-rw-r--r-- 1 joeblow users 0 Jun 14 16:32 textfile


Why would lines that do not contain ".s" be listed??

Thanks,
-dog

# 2  
Old 06-18-2011
try
Code:
grep -n "\.s" textfile

This User Gave Thanks to sk1418 For This Post:
# 3  
Old 06-18-2011
Hi
grep .s means to grep for the pattern: ' any character(.) followed by s". In your case, the lines containing the word "users" in the group section get satisfied by your search pattern, and hence the below result.

Guru.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Strange Script behaviour with Grep

Here is my script LOGDATE=`date '+%Y-%m-%d %k:%M' | cut -c1-15` echo $LOGDATE echo "grep '$LOGDATE' /tmp/logs/vel.log >10min_log" grep '$LOGDATE' /tmp/logs/vel.log>10min_log grep '$LOGDATE' /tmp/logs/vel.logHere is the output of the script -rw-r--r-- 1 wluser wluser 0 May 3... (7 Replies)
Discussion started by: mohtashims
7 Replies

2. UNIX for Dummies Questions & Answers

Strange behaviour of grep in SunOS

Hi I ahve 2 files with below content: cat file1 FILE3 test1 test2 cat file2 file3 ghg test1 test2 i want to use file1 as pattern file and find out the missing strings in file2.(i.e ghg in this case regardless of c ase) I have tried: grep -i -v -f /path/file1 /path/file2 (6 Replies)
Discussion started by: pandeesh
6 Replies

3. Shell Programming and Scripting

Explanation for interesting sed behaviour?

This is my first post so hi to you all. I have browsed these forums in the past and what a great community and resource this is! Thanks to all the contributors ... I look forward to being able to give something back. In the meantime, I have a little conundrum concerning sed. My very simple... (6 Replies)
Discussion started by: Gavster
6 Replies

4. Shell Programming and Scripting

interesting problem

Hi, I am new in this forum and I am glad to be a part of it. I have a problem that has two parts: 1/ extract just the timestamp from a filename: for example, I have a file called 'sales20080226144525.txt' and I want to extract just the '20080226144525' part out of it. 2/ Now, take that... (5 Replies)
Discussion started by: ChicagoBlues
5 Replies

5. Shell Programming and Scripting

Interesting problem

Hello, So I'm utilizing the bash brace expansion feature to checkout multiple folders from cvs with ease, while excluding certain subfolders within. So I do a command like this: cvs co trunk/{mod_a,mod_b,mod_c} \!trunk/{mod_a,mod_b,mod_c}/web to checkout modules trunk/mod_a , trunk/mod_b ,... (1 Reply)
Discussion started by: neked
1 Replies

6. What is on Your Mind?

How can I get some interesting books?

I am not a native English speaker. I wanna improve my English. But I am kind of lazy, so I decide to pratice my English by reading English novel. I'd like read books about magic or superman and so on. How can I get that kind of books from Internet? I'll really appreciate it!! (4 Replies)
Discussion started by: virmin
4 Replies

7. UNIX for Dummies Questions & Answers

Some interesting questions

Hello All, I have some questions; 1) process1 | process2, A)now if I kill process2 what happens to process1? B) if I kill process1 what happens to process2? 2) Why kill -9 is a strong kill? If possible I would like to know what happens internally. 3) What a pipe actually do, in... (3 Replies)
Discussion started by: willhunter
3 Replies

8. UNIX for Advanced & Expert Users

interesting problem

After a server reboot for regular mainatanance we face the following situation: 1/ user accounts with ksh can't start the korn shell 2/ korn shell scripts do work however, if executed from bash 3/ normal users with bash can't run ksh 4/ root can run ksh 5/ if I switch the default shell to... (3 Replies)
Discussion started by: rein
3 Replies
Login or Register to Ask a Question