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
  • 152,036
  • 28
  • 249
  • 266
Paul Dawson
  • 1,332
  • 14
  • 27

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
  • 10,247
  • 7
  • 47
  • 64
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,195
  • 5
  • 27
  • 38
1
awk '{$5=""; $10=""; print}' file
www.bob.com | Jul 28  2015 | Jul 27  2017
Claes Wikner
  • 1,457
  • 1
  • 9
  • 8
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
  • 761,203
  • 64
  • 569
  • 643