Problem with sed wildcard "*" | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Unix/Linux Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Problem with sed wildcard "*"

UNIX for Dummies Questions & Answers


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-03-2012
mukulverma2408 mukulverma2408 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 4 September 2014, 7:17 AM EDT
Posts: 61
Thanks: 12
Thanked 2 Times in 2 Posts
Problem with sed wildcard "*"

Hi All,
can you help me with "*" wildcard character in sed, i am a bit confused. I am going through a reference and found that below code

Code:
sed -n '/a*c/' file

will also return a line that contain the string

Code:
output :
close the window properly

how is that possible when there is no "a" in this string?? how does this wildcard works.
Any reference/suggestion would be appreciated.
Sponsored Links
    #2  
Old Unix and Linux 12-03-2012
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 27 March 2015, 5:39 PM EDT
Location: Foxborough, MA
Posts: 7,762
Thanks: 170
Thanked 632 Times in 590 Posts
a* - zero or more occurrences of a
Sponsored Links
    #3  
Old Unix and Linux 12-03-2012
in2nix4life's Unix or Linux Image
in2nix4life in2nix4life is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 9 March 2015, 3:43 PM EDT
Location: East Coast
Posts: 618
Thanks: 1
Thanked 177 Times in 163 Posts
It's capturing the 'c'. If you change the 'c' to a 'z', then nothing will be returned since there is neither an 'a' or 'z' in the string.


Code:
$ sed -n '/a*c/p' file
close the window properly

$ sed -n '/a*z/p' file
$

    #4  
Old Unix and Linux 12-03-2012
mukulverma2408 mukulverma2408 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 4 September 2014, 7:17 AM EDT
Posts: 61
Thanks: 12
Thanked 2 Times in 2 Posts
Quote:
Originally Posted by vgersh99 View Post
a* - zero or more occurrences of a
Hi Vgresh, My output doesn't contain any occurrence of "a"

---------- Post updated at 11:52 PM ---------- Previous update was at 11:46 PM ----------

Thanks in2nix4life,
Quote:
It's capturing the 'c'. If you change the 'c' to a 'z', then nothing will be returned since there is neither an 'a' or 'z' in the string.
Yes i do understand that its capturing the 'c', but my problem is to understand the functionality of '*'. How does it work, and what does it really look for in a string??
Sponsored Links
    #5  
Old Unix and Linux 12-03-2012
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 27 March 2015, 5:39 PM EDT
Location: Foxborough, MA
Posts: 7,762
Thanks: 170
Thanked 632 Times in 590 Posts
Quote:
Originally Posted by mukulverma2408 View Post
Hi Vgresh, My output doesn't contain any occurrence of "a"
as I said, 'a*' stands for zero or more occurrences of a.
If you want to get lines where an 'a' is followed by anything and a 'c': a.*c
Sponsored Links
    #6  
Old Unix and Linux 12-03-2012
mukulverma2408 mukulverma2408 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 4 September 2014, 7:17 AM EDT
Posts: 61
Thanks: 12
Thanked 2 Times in 2 Posts
Thanks Vgresh for your quick help, but i think i am not able to explain my problem properly.
can you please also explain a bit about '*' in sed?
I tried but i am really getting confused with this.
Sponsored Links
    #7  
Old Unix and Linux 12-03-2012
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 27 March 2015, 5:39 PM EDT
Location: Foxborough, MA
Posts: 7,762
Thanks: 170
Thanked 632 Times in 590 Posts
Quote:
Originally Posted by mukulverma2408 View Post
Thanks Vgresh for your quick help, but i think i am not able to explain my problem properly.
can you please also explain a bit about '*' in sed?
I tried but i am really getting confused with this.
Why don't you explain what you're actually after?
What exactly are you trying to do?
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to use "cut" or "awk" or "sed" to remove a string timmywong Shell Programming and Scripting 8 02-12-2012 11:55 AM
cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' harshakusam Shell Programming and Scripting 4 08-25-2009 11:21 AM
A question/problem about oracle "tns listener" and "enterprise manager" talipk UNIX for Advanced & Expert Users 1 12-03-2008 06:55 AM
A question/problem about oracle "tns listener" and "enterprise manager" talipk UNIX and Linux Applications 0 12-01-2008 02:08 PM
Preventing wildcard expansion in "read" gaijin 06 UNIX for Dummies Questions & Answers 8 11-01-2005 08:31 PM



All times are GMT -4. The time now is 06:08 PM.