Monday, April 8, 2013

SED / AWK

sed options
  • s - substitute
  • i - insert
  • a - append
  • d - delete
To pass a file with sed commands:
  • sed -f sample.sed file.txt
Replace from the beginning of line
  • sed 's/^night/day/'
Replace from end of line
  • sed 's/ $//' - Replace space at end of line
 Delete lines of file.txt, starting with line X
  • sed 'X,$d' file.txt


Remove all white space from beginning of line
  • echo "     This is a test" | sed -e 's/^[ \t]*//'

 Edit a file in place:
  • sed -i 's/BOB/JANE/' file.txt
Removing most things in between ( and ) in a file
  •  sed 's/([a-z,A-Z,0-9,+*!]*)//g'
Remove empty lines from a file:
  • sed '/^$/d'
 Remove everything except the number one....
  • sed 's/[^1//g'

No comments:

Post a Comment