WebSphere Issues


sed and awk commands

Filed under: Other — Ishtiaque @ 2:10 pm

1. sed:

  • sed -i s/string1/string2/g file.txt (Replace all occurrences of string1 with string2 and save the file)
  • sed s/pattern/replace_string/ file.txt (Replace first occurrence of string1 with string2)
  • sed 1,3s/pattern/replace_string/g file.txt (Replace all occurrences of string1 with string2 from lines 1 to 3)
  • sed -e ‘s/01/JAN/’ -e ‘s/02/FEB/’ -e ‘s/03/MAR/’ file.txt

2. awk:

  • awk ‘{ print $0 }’ /etc/passwd      (Prints entire file)
  • awk -F: ‘{ print $1 }’ /etc/passwd  (Prints first field of every line)
  • awk -F: ‘{ print $1 $6 }’ /etc/passwd (Prints first and sixth field of every line)

Create a free website or blog at WordPress.com.

%d bloggers like this: