ls grep query


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers ls grep query
# 8  
Old 06-19-2010
It makes no difference here
Code:
$ ls | grep f*.
abc
def
hij

So what did you mean by "I changed the question a bit but I don't think it would have made any difference..."?
# 9  
Old 06-19-2010
Quote:
Originally Posted by scottn
It makes no difference here
Code:
$ ls | grep f*.
abc
def
hij

So what did you mean by "I changed the question a bit but I don't think it would have made any difference..."?
Here you go

The following command is executed:

$ ls
defer dir1 dir3 file2 fileb flower list script1
defer2 dir2 file1 filea filec fruit output veg
You execute the command:


ls | grep f*.


Which files will be displayed?


A. All of the files. B. Only the files that begin with an f. C. All of the files that contain an f. D. None of the files.







The Answer is showing as



Answer A is incorrect. None of the files will be displayed

Answer B is incorrect. None of the files will be displayed

Answer C is incorrect. None of the files will be displayed

Answer D is correct. None of the files are displayed as the shell has matched the pattern f*, so the command has no output to check against


# 10  
Old 06-19-2010
The answer may or may not be correct.

If the dot is actually part of the question, as you said, then the answer is wrong - regardless of globbing.

If the dot is not part of the question and globbing is on, then the answer is correct.

Code:
$ set +f # globbing is on
$ ls | grep f*.
defer
defer2
dir1
dir2
dir3
file1
file2
filea
fileb
filec
flower
fruit
list
output
script1
veg

$ ls | grep f*
(no output)

$ set -f

$ ls | grep f*.
defer
defer2
dir1
dir2
dir3
file1
file2
filea
fileb
filec
flower
fruit
list
output
script1
veg

$ ls | grep f*
defer
defer2
dir1
dir2
dir3
file1
file2
filea
fileb
filec
flower
fruit
list
output
script1
veg

# 11  
Old 06-19-2010
thanks for that....I'm going to have a think about it down the pub!
# 12  
Old 06-21-2010
Code:
Where there are no files which match the pattern "f*." shell expands this to a null string. Thus:
ls | grep f*.

Expands to
ls | grep ''

Which lists all files.


A file in the directory with a name starting with "f" and ending in "." changes the behaviour.
# 13  
Old 06-21-2010
Quote:
Originally Posted by methyl
Code:
Where there are no files which match the pattern "f*." shell expands this to a null string. Thus:
ls | grep f*.
 
Expands to
ls | grep ''
 
Which lists all files.


A file in the directory with a name starting with "f" and ending in "." changes the behaviour.
I just created a file starting with "f" and ending in "." and it does appear to change the behaviour...but can you tell me why that is?

thanks
# 14  
Old 06-26-2010
I just had a look at some other questions and none of them end in a period....so the dot at the end of the above question is intentional!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

File grep quick query

Hi Experts, I need some suggestion on file grep. I am trying to find multiple pattern with the file grep as below grep "2013" trace.log | grep -f pattern.cfg -i > $LOG if ; then mail -s "Exception" "sample@abc.com" < $LOG fi Is it possible to obtain what pattern I got in the... (5 Replies)
Discussion started by: senthil.ak
5 Replies

2. Shell Programming and Scripting

Grep query

Hi, What does this line do grep -E 'ORA-' $LIN_TOP/log/status.log > /dev/null 2>&1 Does this check in status.log and in std out, stderr also.? Thanks (3 Replies)
Discussion started by: nag_sathi
3 Replies

3. Shell Programming and Scripting

grep command query

list ALL file entries with a last modification date of September 20. using grep (1 Reply)
Discussion started by: polineni
1 Replies

4. UNIX for Dummies Questions & Answers

query related to grep

Hi All, The result for 'grep "cert_codes" /develop/sales/appl.srce/*.4gl' command will be saved at aa.txt grep "cert_codes" /develop/sales/appl.srce/*.4gl >aa.txt But I am not sure, whether, all result stored in .txt file in case of multi-line result. Please revert back if... (2 Replies)
Discussion started by: pbankar
2 Replies

5. Shell Programming and Scripting

grep/sed query

Hi all, I have one query,in my script,i give one input like sectionname that enclose with and that will search in specific file in specific directory.If found ,then it's search next section and begin of section ,sometext means different sectionname. p1 p2 p3 p4 p5 p6 I want to... (2 Replies)
Discussion started by: suryanarayan
2 Replies

6. Shell Programming and Scripting

Grep query

As part of my never-ending nagios automation project I am need to implement the following run line into a loop; -bash-3.00$ grep ${feed} /usr/local/feed/service/clients/*/bin/* | awk -F/ '{print "To restart: /"$2"/"$3"/"$4"/"$5"/"$6"/"$7"/"$8"/"$9}' Which prints to screen; To restart:... (3 Replies)
Discussion started by: JayC89
3 Replies

7. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

8. Shell Programming and Scripting

grep command query

Hi I have file like this: Sun Jan 24 03:00:00 2010: *** Weekly Process - get_ens_files.pl START *** Sun Jan 24 03:00:00 2010: *** *** Sun Jan 24 03:00:00 2010: *************************************************** Sun Jan 24 03:00:11 2010: ... (2 Replies)
Discussion started by: koti_rama
2 Replies

9. Shell Programming and Scripting

Query regarding grep

In what cases the following command ignores lines in input file: $ grep -c "^" inputfile (1 Reply)
Discussion started by: amicon007
1 Replies

10. UNIX for Dummies Questions & Answers

query on grep command

Hai Friends Can anyone provide me a grep command to print x to y lines in a file. For example: grep command to display 15th line to 21st Thanks in advance Collins (4 Replies)
Discussion started by: collins
4 Replies
Login or Register to Ask a Question