Skip to content

Latest commit

 

History

History
46 lines (23 loc) · 971 Bytes

Session6.md

File metadata and controls

46 lines (23 loc) · 971 Bytes

Regex applications

Use of sed for stream editing of text

Use of -n to supress lines that do not match

  sed ',Ap' RollList.csv

  sed -n ',Ap' RollList.csv

Use of regex in sed

  sed 's,A,ap' RollList.csv

  sed -n 's,A,ap' RollList.csv

Strip the roll number

  sed -n 's/....B...,//p' RollList.csv

  sed -n 's.\*,//p' RollList.csv

Strip the name

  sed -n 's/,.*//p' RollList.csv

Use of sed to edit a stream of lines

  cat RollList.csv | sed -e 's/^.*,//g'

  cat RollList.csv | sed -e 's/^.*,//g' > n.txt

  cat RollList.csv | sed -e 's/,.*//g' > r.txt

Use of brackets to store fields

  cat RollList.csv | sed -e 's/^\(.*\),\(.*\)$/\2,\1/g'

Changing case of fields

  cat RollList.csv | sed -e 's/^\(.*\),\(.*\)$/\2,\L\1/g'

Changing case of fields and adding text that makes the roll number appear as an email address.

  cat RollList.csv | sed -e 's/^\(.*\),\(.*\)$/\2,\L\[email protected]/g'