Pages tagged with sed

  • Newline conversion from DOS/Windows to Unix/Linux - To convert DOS/Windows newlines (CRLF) to Unix/Linux newlines (LF): sed 's/^M$//' Important: To generate the ^M type ctrl-v-m, not the ^ character followed by M.
  • Text manipulation - cut, awk and sed - Tokenize strings using cut If you know the exact delimiter (e.g. a tab) you can use cut. The format is cut -ddelimiter -ffield_number filename where delimiter is the delimiter, field_number is the number of the field we want and filename is ...
  • Escape spaces with sed - When dealing with file paths, you may need to escape spaces. You can do this using sed. #!/bin/sh p = "/var/lib/vmware/Virtual Machines" echo $p q = $(echo $p | sed 's/ /\\ /g') echo $q Output: /var/lib/vmware/Virtual Machines /var/lib/vmware/Vi...
  • Find and replace text in multiple files - As always, back up all files before doing this. In the regexp, remember to escape the necessary characters, e.g. slashes. Use the find command to list all files matching the criteria and pipe through xargs to perl to find and replace the text with a ...
  • Find and replace - Find ignoring a file In this example excluding todo.txt prevents an infinate loop that would otherwise result in todo.txt growing to fill all space on the hard disk. find . -type f \( -name "*.txt" ! -name "todo.txt" \) -exec grep "TODO" -iHn {} \; &...
  • Extract filenames from file - grep for word in file | remove spaces | remove unwanted text | do op on file grep whatever whatever.log | sed 's/ /\\ /g' | sed 's/whatever//g' | xargs ls -l Example: List infected files clamscan -r -lclamscan.log / recursively scans all files and ...
Go to top

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top