Sponsored Content
Top Forums Shell Programming and Scripting Unable to grep using wildcard in a file. Post 303041850 by mohtashims on Thursday 5th of December 2019 08:14:35 AM
Old 12-05-2019
Unable to grep using wildcard in a file.

I wish to check if my file has a line that does not start with '#' and has
1. Listen and 2. 443

Code:
 echo "Listen               443" > test.out

grep 'Listen *443' test.out | grep -v '#'
Listen               443

The above worked fine but when the entry changes to the below the grep fails when i dont want it to fail.

Code:
echo "Listen     192.888.22.111:443" > test.out

Also, i do grep -v '#' to ignore lines having # i.e comments but is there a way to check if # is the starting (not necessary the first character considering there are whitespaces before the #) charecter in the line only then it should be ignored else be considered by the grep query.

So....

Quote:
# Listen 192.888.22.111:443
should not be considered

But

Quote:
Listen 192.888.22.111:443 #
should be considered.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find wildcard .shtml files in wildcard directories and removing them- How's it done?

I'm trying to figure out how to build a small shell script that will find old .shtml files in every /tgp/ directory on the server and delete them if they are older than 10 days... The structure of the paths are like this: /home/domains/www.domain2.com/tgp/ /home/domains/www.domain3.com/tgp/... (1 Reply)
Discussion started by: Neko
1 Replies

2. Shell Programming and Scripting

Grep with wildcard in middle of word

How can grep G.*schema give me the result: ${Gacntg_dt}""'"' doesn't G.*schema say give me an unlimited number of characters between G and schema? :confused: (3 Replies)
Discussion started by: danmauer
3 Replies

3. Shell Programming and Scripting

Log file is not getting created & unable to grep error from it

Hi All, Below is my code,what I am trying to do is redirecting output of ftp to a log file & then greping the errors but here I am unable to grep "Permission denied" error only & also the corresponding log file is also not getting created. #!/bin/sh . cfg USER='abc' PASSWD='abc123' ... (4 Replies)
Discussion started by: ss_ss
4 Replies

4. UNIX for Dummies Questions & Answers

Tail command with wildcard file name

Please help with the following command tail -f /appdata/logs/alert_audit517.txt | grep "Sep 02" The problem I have is with the file name "alert_audit517.txt". The 3 digit number at the end of the file name changes, so I need the file name to use a wildcard. Ive tried alert_audit***.txt, but... (5 Replies)
Discussion started by: robertson1995
5 Replies

5. Shell Programming and Scripting

wildcard inside regular expression for grep

Hi, I'm on a Linux machine with a bash shell. I have some apache logs from where I want to extract the lines that match this pattern : "GET /dir1/dir2/dir3/bt_sx.gif HTTP/1.1" but where "/dir1/dir2/dir3/bt_sx" may vary , so I would like to grep something like cat apache.log | grep "\"GET... (2 Replies)
Discussion started by: black_fender
2 Replies

6. Shell Programming and Scripting

Grep Wildcard search

How can i grep for a pattern with wildcard using grep? I want to identify all the lines that start with SAM and end in .PIPE IN.TXT SAM_HEADER.PIPE SAM_DETAIL.PIPE SAM_INVOICE.PIPE Can i do something like grep SAM*.PIPE IN.TXT (2 Replies)
Discussion started by: venky338
2 Replies

7. Shell Programming and Scripting

Wildcard for grep

GNU grep with Oracle Linux 6.3 I want to grep for strings starting with the pattern ora and and having the words r2j in it. It should return the lines highlighted in red below. But , I think I am not using wildcard for multiple characters correctly. $ cat someText.txt ora_pmon_jcpprdvp1... (3 Replies)
Discussion started by: kraljic
3 Replies

8. UNIX for Dummies Questions & Answers

Wildcard in file names

I know this is very basic and looks strange to me . -bash-3.2$ wc -l *. Result: 51 test.bad Since my third range after dot is A-Z(upper), how it matched the d( Lower)? i was in an understanding that the above code would not fetch any result unless i have a file with 3 char extension... (4 Replies)
Discussion started by: saravana.sarak
4 Replies

9. Shell Programming and Scripting

Grep and BzGrep with Wildcard in Search Pattern

Hello All, I hope this is the right area. If not, Kindly let me know and I will report in the appropriate spot. I am needing to find a search pattern that will make the * act as Wildcard in the search pattern instead of being literal. The example I am using is bzgrep "to=<*@domain.com>"... (5 Replies)
Discussion started by: mancountry
5 Replies

10. Shell Programming and Scripting

Grep with wildcard

hi anyone how can use grep with wildcard. for example grep "sample?txt" filename doesn't show sample1txt or grep "sample*txt" filename doesn't show sample123.txt that there is in filename. many thanks samad (12 Replies)
Discussion started by: abdossamad2003
12 Replies
ZGREP(1)                                                      General Commands Manual                                                     ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 02:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy