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

  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 Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-03-2012
mukulverma2408 mukulverma2408 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 20 August 2014, 4:07 AM EDT
Posts: 59
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 12-03-2012
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 22 August 2014, 5:24 AM EDT
Location: Foxborough, MA
Posts: 7,644
Thanks: 150
Thanked 577 Times in 542 Posts
a* - zero or more occurrences of a
Sponsored Links
    #3  
Old 12-03-2012
in2nix4life's Avatar
in2nix4life in2nix4life is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 21 August 2014, 4:19 PM EDT
Location: East Coast
Posts: 610
Thanks: 1
Thanked 175 Times in 161 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 12-03-2012
mukulverma2408 mukulverma2408 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 20 August 2014, 4:07 AM EDT
Posts: 59
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 12-03-2012
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 22 August 2014, 5:24 AM EDT
Location: Foxborough, MA
Posts: 7,644
Thanks: 150
Thanked 577 Times in 542 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 12-03-2012
mukulverma2408 mukulverma2408 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 20 August 2014, 4:07 AM EDT
Posts: 59
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 12-03-2012
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 22 August 2014, 5:24 AM EDT
Location: Foxborough, MA
Posts: 7,644
Thanks: 150
Thanked 577 Times in 542 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 Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 05:50 AM.