grep command does not work


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep command does not work
# 1  
Old 08-04-2012
grep command does not work

Hello.
I have a question as to why my grep command does not seem to be working.
Code:
grep -c '^[K]?*' ~

Code:
grep -c '^[K].*' ~

I wanted to count the number of files starting with the letter K and have some letters after that. I have such files in my home directory. However, the output is 0. So, I have no ideas why it makes the wrong output. Thanks in advance!!! Smilie
# 2  
Old 08-04-2012
Directories aren't text files and the filenames stored in directories won't usually appear to be at the start of a line. Try:
Code:
ls ~|grep -c '^K'

This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 08-04-2012
Quote:
Originally Posted by Don Cragun
Directories aren't text files and the filenames stored in directories won't usually appear to be at the start of a line. Try:
Code:
ls ~|grep -c '^K'

Thanks a lot!!! Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep doesn't work when assigning to variable

Hello, First of all, I'd like to say hello to all members of forum. Can You please help me with the matter described below? I am trying to fetch a data from the file to variable, I am doing this using below script: returned=`tail -50 SapLogs.log | grep -i -E "Error|"` echo $returned ... (2 Replies)
Discussion started by: jedzio
2 Replies

2. Shell Programming and Scripting

grep -o does not work in Solaris

I am using the code below to grep through a list of files (TEMPFILE) and look for rsync, rdist, rsh, ftp, etc. in each file. Do a count of each, and output that to a logfile. This works great in Linux, but not at all in Solaris because the EGREP -o option does not exist. Anyone have an idea... (5 Replies)
Discussion started by: nitrobass24
5 Replies

3. Shell Programming and Scripting

Cannot get grep to work within function.

Hello again, Am having an issue now with getting a simple grep command to work within a function.. The function is as below... function findRecord() { output=grep "001" recordDatabase echo $output } At the moment the "001"... (3 Replies)
Discussion started by: U_C_Dispatj
3 Replies

4. Solaris

Creating script - grep wont work?

This is my first script and I wont get it working.. sorry for being a total noob but here it is: #./bin/sh -x echo "1:st argument = $1"; echo "2:nd argument = $2"; grep "$1" "$2" In the terminal I write, for example, su.sh sausage sausage.txt Also tried su.sh "sausage" "sausage.txt" but... (2 Replies)
Discussion started by: Prantare
2 Replies

5. Shell Programming and Scripting

tail -XXX with grep doesn't work in while loop

Hi all, I need some help. my shell script doesn't work especially in the loop. #!/bin/sh -xv export ORA_ADMIN=/oracle/home/admin export ORACLE_SID=ORA_SID cat ${ORA_ADMIN}/param_alert_log.ora | while read MSG do #echo $MSG #echo "tail -400... (8 Replies)
Discussion started by: sidobre
8 Replies

6. Shell Programming and Scripting

two grep in one script doesn't work?

Hi there, the following script doesn't work. the first part works, then the second 'grep' fails with ': not found'. However, if I take out the second part (starting with the grep command) and put in a seperate script, it works. everyone know what's wrong here? no two 'grep' in one script, that... (2 Replies)
Discussion started by: monkey77
2 Replies

7. UNIX for Dummies Questions & Answers

For some reason, my grep doesn't work as expected

I am trying to find only those entries where 7018 and another number appear in the end of the line. 7018 2828 1423 2351 7018 2828 14887 2828 7018 1222 123 7018 1487 I am looking for a way to generate only the last two lines. I was trying to do just "grep '7018{1,5}" but it does not... (5 Replies)
Discussion started by: Legend986
5 Replies

8. Solaris

grep -e doesn't work on solaris

grep -e doesn't work in Soalris. Same script with grep -e worked on AIX/HP/LINUX.. I would like to search a list of patterns on "log.txt" like ... grep -e FATAL -e ERROR log.txt I get the error message as grep: illegal option -- e Usage: grep -hblcnsviw pattern file . . . (3 Replies)
Discussion started by: jmkraja
3 Replies

9. UNIX for Dummies Questions & Answers

Why does this grep not work?

Hi Could you please tell me why the following grep does not match the string? > echo ' 1661 Rows not loaded because all WHEN clauses were failed.' | grep 'Row* not*WHEN*' Thanks gnmike (2 Replies)
Discussion started by: GNMIKE
2 Replies

10. Shell Programming and Scripting

grep doesn't work within shell script?

I am trying to run the following code from a script file but it complains that syntax of (both instances of) grep is wrong. When I copy and paste it to the terminal, it is OK. Any idea what the problem might be? set i = `grep -c #define flags.h` while ($i>20) @ i-- my func (`cat... (4 Replies)
Discussion started by: barisgultekin
4 Replies
Login or Register to Ask a Question