13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 9 ■ WORKING WITH TEXT IN FILESCharacterexp+exp?DescriptionOne or more strings matching the expression exp (so A+ matches one ormore A characters).Zero or one strings matching the expression exp (so A? matches zero orone A characters).[A-Za-z0-9] Any alphanumeric character (A–Z, a–z, 0–9).\w Any word character (A–Z, a–z, 0–9, plus the underscore).\W Any nonword character (punctuation except underscore and spacecharacters).\d Any digit character.\t Tab.\n Newline.\b A word boundary: matches if the character to the left is a wordcharacter and the character to the right is not, or vice versa.\B Not a word boundary: matches if the characters to right and left areboth word characters or nonword characters.You can also make the replacement only on particular lines:sed -e '1,20s/foo/bar/g' test.txt■ Note Remember that sed works only on a line at a time. If you’re searching for a long phrase that might breakacross lines, then you may end up missing some of them. It’s possible to use the hold buffer to read multiple linesinto memory and check them. See http://www.grymoire.com/Unix/Sed.html for more on this.9-2c. Appending, Inserting, and Changing LinesIf you have an LDAP setup, you may want to add a line to an entry or to multiple entries. See Chapter 2for discussion of how to query LDAP, but once you have a file containing the DN of the entries that youwant to change in this format:dn: cn=machine1,ou=Hosts,dc=example,dc=comdn: cn=machine2,ou=Hosts,dc=example,dc=com190Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!