Advertisement
kremisoski

Search and Replace with sed in Linux

May 26th, 2015
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.47 KB | None | 0 0
  1. # Searches all csv files in directory for pipes and replaces them with commas ("|" with ",")
  2. # sed basic usage
  3. # sed -i 's/foo/bar/g' FILENAME (s tells sed to search, foo = search string, bar = replace string, g = all chars on each line)
  4. # special characters like commas require an escape e.g. \, but not all special chars for example a pipe '|' does not
  5. # it is best to wrap this in a for loop to avoid breaking command line limits
  6.  
  7. for i in *csv; do
  8.     sed -i 's/|/\,/g' $i
  9. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement