1

Hello sed/awk/bash experts,

I have thousands of certs to report on and I want to remove the time:

www.bob.com  | Jul 28 19:22:38 2015   | Jul 27 19:22:38 2017 

How can I (easily) remove 19:22:38 & 19:22:38 so I just have:

www.bob.com  | Jul 28 2015 | Jul 27 2017 
hek2mgl
  • 143,113
  • 25
  • 227
  • 253
Paul Dawson
  • 1,282
  • 12
  • 26

4 Answers4

1

If you're using an older version of sed you could try the following:

$ echo "www.bob.com  | Jul 28 19:22:38 2015   | Jul 27 19:22:38 2017" | sed 's/\([a-zA-Z]*[ ]*[0-9]*[ ]*\)[0-9:]*\([ ]*[0-9]*\)/\1\2/g'
www.bob.com  | Jul 28  2015   | Jul 27  2017

Or perhaps to just remove the time, you could instead use:

echo "www.bob.com  | Jul 28 19:22:38 2015   | Jul 27 19:22:38 2017" | sed 's/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]//g'
www.bob.com  | Jul 28  2015   | Jul 27  2017
Component 10
  • 9,937
  • 5
  • 44
  • 62
1

If you want to edit the file in place rather than just outputting to the screen, use a modified version of anubhava's command:

sed -E 's/[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}[[:blank:]]+//g' file > file.tmp && mv file.tmp file

It also has the added benefit of not wiping your original file should sed fail. See here.

Community
  • 1
  • 1
docksteaderluke
  • 2,105
  • 5
  • 27
  • 36
1
awk '{$5=""; $10=""; print}' file
www.bob.com | Jul 28  2015 | Jul 27  2017
Claes Wikner
  • 1,397
  • 1
  • 8
  • 7
0

Using sed:

sed -E 's/[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}[[:blank:]]+//g' file

www.bob.com  | Jul 28 2015   | Jul 27 2017
anubhava
  • 713,503
  • 59
  • 514
  • 593