Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
03-03-2010, 06:52 PM
|
#1
|
|
Member
Registered: Mar 2004
Location: Tokyo, Japan
Distribution: Backtrack 5 R3
Posts: 125
Rep:
|
Sed qestion - how to use wildcards
I'm finally learning how to use sed and I can't find an answer to this but I'm sure it's basic.
I have a file name of student names and their homerooms. The 3rd year students just graduated so I want to change their homeroom status to 'graduated'. This is a sample:
Yuko Myoji 31
Maiko Nanikashira 31
Ema Shiranai 32
Airi Dosuru 33
If I run sed s/31/graduated/g it will change all students in 31 to graduated, but how do I do that for 3x (i.e., students in homerooms 31, 32, 33 and 34?)
I tried sed s/31/graduate/g name.txt >> updatednames.txt, then did the same thing for s/32, s/33 and s/34, but the file repeats the whole list each time, so I know I'm doing something wrong.
|
|
|
|
03-03-2010, 07:26 PM
|
#2
|
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,797
|
In utilities like SED, what you call "wildcards" are part of the syntax of Regular Expressions (AKA Regexes).
In your example, you could use:
Code:
sed 's/3[0-9]/graduated/' filename
## This matches all occurences of "3", following by one numeral
For good tutorials on SED, Regexes, and more, go here:
http://www.grymoire.com/Unix/Sed.html
|
|
|
|
03-04-2010, 01:22 AM
|
#3
|
|
Member
Registered: Mar 2004
Location: Tokyo, Japan
Distribution: Backtrack 5 R3
Posts: 125
Original Poster
Rep:
|
Quote:
Originally Posted by pixellany
In utilities like SED, what you call "wildcards" are part of the syntax of Regular Expressions (AKA Regexes).
In your example, you could use:
Code:
sed 's/3[0-9]/graduated/' filename
## This matches all occurences of "3", following by one numeral
For good tutorials on SED, Regexes, and more, go here:
http://www.grymoire.com/Unix/Sed.html
|
Yeah, I knew I didn't have the lingo quite right. I still tend to think of everything I do at the command line as mere commands with switches and wildcards. I forget that grep, sed, etc are actually using expressions. Thanks for that and for the code! Big help!
|
|
|
|
03-04-2010, 09:15 PM
|
#4
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 14,963
|
Actually, even the bash 'wildcards' are in fact expressions; there's more to them than you think..

|
|
|
|
03-04-2010, 09:52 PM
|
#5
|
|
Member
Registered: Mar 2004
Location: Tokyo, Japan
Distribution: Backtrack 5 R3
Posts: 125
Original Poster
Rep:
|
Yes, true
Quote:
Originally Posted by chrism01
Actually, even the bash 'wildcards' are in fact expressions; there's more to them than you think..

|
You're right, I need to stop being so myopic. Bash is really like a mini-programming environment, anyway, right?
|
|
|
|
03-04-2010, 09:55 PM
|
#6
|
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,797
|
Quote:
Originally Posted by kuriharu
You're right, I need to stop being so myopic. Bash is really like a mini-programming environment, anyway, right?
|
BASH is a very capable scripting language, although possibly not the easiest to learn...
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 03:51 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|