Code University

      "Where tuition is free!"

News | Images | Contact     
  • Home
  • Coding KC
  • Scripts
  • Software
  • Templates
  • Tutorials
  • About
 

Coding Knowledge Center

Sed


Page Contents
[X] CLOSE

Subsititution

  • Subsititution (script)
  • Subsititution (simple)
  • Subsititution (to file)
Toggle Page Contents
Subsititution (script)Copy  To New Window  Top ^
#!/bin/bash for file in $(find . -type f -name '*\.php') do sed 's/[from]/[to]/g' $file > $file.tmp mv $file.tmp $file done
Gets a listing of all files in the current working directory with .php as an extension. Then it loops through each file, substituting the text specified in [from] to the text specified in [to]. The output is written to a temporary file which then overwrites the original file.



Subsititution (simple)Copy  To New Window  Top ^
sed 's/[from]/[to]/' [filename]
Substitutes the text specified in [from] to the text specified in [to] then sends it to standard output.



Subsititution (to file)Copy  To New Window  Top ^
sed 's/\([0-9]\{5\}\)=11/\1=05/g' [filename-in] >> [filename-out]
Substitutes all lines in [filename-in] with pattern of "5 digits=11" to "5 digits=05", storing the 5 digits and then reusing it in the substitution, then sends each line to [filename-out].
Technologies
  • Introduction
  • Awk
  • Bash
  • Cron
  • CSH
  • CSS
  • CVS
  • FTP
  • FTPS
  • HTML
  • JavaScript
  • KSH
  • Linux
  • Linux (Debian)
  • Linux (LPIC 101-102)
  • Linux/Unix
  • Mac OS X
  • MySQL
  • Oracle
  • Perl
  • PGP
  • PHP
  • Sed
  • SQLite
  • SSH/SCP/SFTP
  • Telnet
  • UNIX
  • Windows
Resources
  • CodeIgniter - MVC Framework
  • HowtoForge - Linux Tutorials
  • Linux Today - Linux News
  • Lxer - Linux News Feed
  • Monsterb - Linux, Podcasting
  • MySQL - Databasing
  • Perl - Programming
  • PHP - Programming
  • Systhread - Admin & Programming
  • W3Schools - Web Tutorials
About

Code University contains a wealth of technical information aimed at the computer sciences.


 
Home | Coding KC | Scripts | Software | Templates | Tutorials | About
Top ^
 
© 2007-2012 Code University| Disclaimer
Website template by Arcsin