LinuxQuestions.org
Review your favorite Linux distribution.
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 07-18-2013, 02:11 PM   #1
IneptCoder
LQ Newbie
 
Registered: Jun 2013
Location: my house
Distribution: centos, ubuntu
Posts: 10

Rep: Reputation: Disabled
using wildcard with the sed s/// command


I am trying to substitute all the words ending in a "ing" with nothing (aka removing "ing") so essentially I tried this:

sed s/" *ing "// ./myfile

but it doesn't work. I have also tried using wildcard with sed several other times but it doesn't seem to do what it is supposed to do. I am thinking that I need to quote the wildcard somehow, but I have tried many different ways. Does the sed substitute command support using wildcard? if it does how do I use it?
 
Old 07-18-2013, 02:57 PM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
the wildcard in sed is a strange beast

it is actually looking for " " ( spaces ) and only " " no matter how many

Code:
sed 's/ .*ing//' ./myfile
will do what you want ( well maybe not )
here . is 'wild' for any character
BUT, that will wipe out everything up to the last ing

to avoid this you could limit to just alphas ( so space is not part of the pattern )

Code:
sed 's/[a-Z]*ing//' ./myfile
That will only operate on the first match of each line, to get all matches


Code:
sed 's/[a-Z]*ing//g' ./myfile
Note the g on the end
 
1 members found this post helpful.
Old 07-18-2013, 06:21 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,255

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Well I have read the question a few times and the part that catches my eye is:
Quote:
aka removing "ing"
If we are removing "ing" from all words then the following would suffice:
Code:
sed 's/ing//g' file
Of course the downside here is that you may have a word like "working" so when you remove string you get "work", but it also means that a word like "something"
will become "someth" which is not a word
 
1 members found this post helpful.
Old 07-19-2013, 08:29 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
The real answer is that, no, there are no "wildcards" in sed. Tools like sed and grep use regular expressions, which is a different, more complex, and more powerful beast altogether.

It's well worth the effort to learn at least the basics of regex, as one or another flavor of it is used in most text processing tools and programming languages. Even your bash shell supports it (inside the [[..]] test construct).

Here are a few regular expressions tutorials:
http://mywiki.wooledge.org/RegularExpression
http://www.grymoire.com/Unix/Regular.html
http://www.regular-expressions.info/


As for what you call "wildcards", the *nix version is usually called globbing. Globbing is a much less sophisticated descendant of regex used for matching simple patterns in filenames and strings. Your shell uses it in several ways, particularly for matching multiple files at once, and some other tools like find also support them.

These pages detail the globbing types used in bash. A google search or two with terms like "globbing tutorial" should turn up more info.

globbing
extended globbing


Here are a few useful sed references for you too:
http://www.grymoire.com/Unix/Sed.html
http://sed.sourceforge.net/grabbag/
http://sed.sourceforge.net/sedfaq.html
http://sed.sourceforge.net/sed1line.txt
http://www.catonmat.net/series/sed-one-liners-explained
 
1 members found this post helpful.
Old 07-19-2013, 10:39 AM   #5
IneptCoder
LQ Newbie
 
Registered: Jun 2013
Location: my house
Distribution: centos, ubuntu
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thanks for the help
 
  


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 find and replace with wildcard shak4031 Linux - Newbie 3 08-05-2011 04:17 PM
Can I dereference a wildcard in a command? wjtaylor Linux - General 1 03-31-2011 11:19 AM
Using the CHOWN command with a wildcard. Skillz Linux - General 14 01-25-2010 10:42 AM
sed - multiline search/replace with wildcard troubles Yalla-One Programming 4 12-29-2008 01:01 PM
SED: wildcard expansion in variables Gracie Belle Linux - Newbie 3 02-20-2008 08:43 AM


All times are GMT -5. The time now is 06:40 PM.

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