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. |
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 http://www.grymoire.com/Unix/Sed.html |
Quote:
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! |
Actually, even the bash 'wildcards' are in fact expressions; there's more to them than you think..
;) |
Yes, true
Quote:
|
Quote:
|
All times are GMT -5. The time now is 07:31 AM. |