LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-21-2012, 12:11 AM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Rep: Reputation: 16
sed regex one or none '?'


Yeah So i want to get rid of the comment - I though that if you use '?' in the regex - that is signifies one or nothing - - so if there is one - it would replace it, and if there is not,it would just skip it.

I thought that sed used perl like regex rules.

Code:
casper@ashpcasperinit01 ~ $ grep -i casperserver  /var/ftp/*.commands | awk -F'/' '{print $4}' | sed 's/\.commands:#?//g'
casper3013.1.commands:
casper3013.1.commands:
casper3013.1.commands:
casper3013.1.commands:
casper3013.1.commands:
casper3013.1.commands:
casper3013.1.commands:#
casper3013.2.commands:
casper3013.2.commands:
casper3013.2.commands:
casper3013.2.commands:
casper3013.2.commands:
casper3013.2.commands:
default.commands:


casper@ashpcasperinit01 ~ $ grep -i casperserver  /var/ftp/*.commands | awk -F'/' '{print $4}' | sed 's/\.commands://g'
casper3013.1
casper3013.1
casper3013.1
casper3013.1
casper3013.1
casper3013.1
casper3013.1#
casper3013.2
casper3013.2
casper3013.2
casper3013.2
casper3013.2
casper3013.2
 
Old 06-21-2012, 01:17 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,949

Rep: Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210
You want regex extended - see the manpage.
Won't do what (I think) you want, but you'll get further.

grep has the option for perl regex. All regex is different ...
 
Old 06-21-2012, 01:59 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,777

Rep: Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888
sed and perl regexps are more or less similar, but surely not identical. So if you were unsure, you should read the man page.
From the other hand do not use grep|awk|sed (or similar) chains because it can be solved with one of them, for example with a single awk script. The regexps in awk are also slightly different.
Code:
awk -F/ ' /casperserver/ { gsub(".commands:#?", $4); print $4 } ' /var/ftp/*.commands
will do almost the same (not tested, just copied)



_____________________________________
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
Happy with solution ... mark as SOLVED
(located in the "thread tools")
 
Old 06-21-2012, 09:32 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,550

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
To me it would be the age old story of show us what you start with and then what you would like to finish with, as showing us what does not work is fine from the point of view that you had
a go but does little to help us help you.
 
Old 06-21-2012, 10:11 AM   #5
krazyglue
Member
 
Registered: Oct 2003
Posts: 68

Rep: Reputation: 16
Not 100% sure what your looking for but this should work.

Code:
grep -i casperserver  /var/ftp/*.commands |sed 's!commands:#.*!commands:!'
This looks for "commands:#" and anything after that and subs in "commands:" for it.
 
Old 06-21-2012, 10:44 AM   #6
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,825
Blog Entries: 1

Rep: Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221
Agree with grail. No point in guessing....

We call upon the author to explain.... and provide the actual samples of the original text and the desired end output.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed and regex help zski128 Programming 5 12-13-2011 11:30 AM
sed regex say_hi_ravi Programming 3 09-15-2011 03:12 AM
Help with sed regex homer_3 Linux - General 1 08-18-2009 02:57 PM
regex with sed to process file, need help on regex dwynter Linux - Newbie 5 08-31-2007 06:10 AM
Help with Sed and regex cmfarley19 Programming 6 11-18-2004 02:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration