Skip to main content
added 214 characters in body
Source Link
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

Since all you're doing is adding two dashes, and dropping some extra characters, there's not much need for date.

$ sed -Ee 's/(Last Password Change: )(....)(..)(..).*Z/\1\2-\3-\4/' < foo.txt
...
  Name: cust foo
  mail: [email protected]
  Account Lock: FALSE
  Last Password Change: 2017-07-21
...

For a stricter pattern, the dots (that match any character) could be replaced with [0-9] to only match digits. \1 etc. in the replacement of course expand to what ever the patterns in parenthesis matched.

Since all you're doing is adding two dashes, and dropping some extra characters, there's not much need for date.

$ sed -Ee 's/(Last Password Change: )(....)(..)(..).*Z/\1\2-\3-\4/' < foo.txt
...
  Name: cust foo
  mail: [email protected]
  Account Lock: FALSE
  Last Password Change: 2017-07-21
...

Since all you're doing is adding two dashes, and dropping some extra characters, there's not much need for date.

$ sed -Ee 's/(Last Password Change: )(....)(..)(..).*Z/\1\2-\3-\4/' < foo.txt
...
  Name: cust foo
  mail: [email protected]
  Account Lock: FALSE
  Last Password Change: 2017-07-21
...

For a stricter pattern, the dots (that match any character) could be replaced with [0-9] to only match digits. \1 etc. in the replacement of course expand to what ever the patterns in parenthesis matched.

Source Link
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

Since all you're doing is adding two dashes, and dropping some extra characters, there's not much need for date.

$ sed -Ee 's/(Last Password Change: )(....)(..)(..).*Z/\1\2-\3-\4/' < foo.txt
...
  Name: cust foo
  mail: [email protected]
  Account Lock: FALSE
  Last Password Change: 2017-07-21
...