2

I'm looking for an awk or sed solution, I'm not a genius with either. I have read all of the suggestions that came up when I started typing this up.

I have a file with lines of data:

name
 thisdate=Sep  2 23:59:59 2022 GMT
name
 thisdate=Sep 15 23:59:59 2022 GMT

The names and dates/times are all different, the day numbers are always in the same place and always take up the same number of characters (2), the hours/min/secs are all always in the same position on the line and its not every line, thisdate is always a date in the future, and there are no blank lines.

I am trying to remove the time from those date lines by trying to key off  thisdate= (that's a space in front of thisdate) and then deleting characters in positions 18-26 (if I counted right)

I've tried a couple things but have been mostly searching for something that fits my needs to point me in the right direction

  952  sed 's/^\(.\{18\}\)\(.\{26\}\)/\1/' file  <--this may not have worked as I didn't key on a match?
  958  sed -i 's/thisdate=(.{11})18/\26/' file
  959  sed -i 's/thisdate=(.{10})17/\25/' file

I'm sure I'm missing something but if someone could point me in the right direction I'd be grateful!

1
  • Do you want to keep the GMT part? Commented Apr 13, 2020 at 21:21

1 Answer 1

1

It looks like it should be enough with just deleting 9 characters after the 6th character after  thisdate=:

sed 's/^\( thisdate=.\{6\}\).\{9\}/\1/' file

For the given data, this would generate

name
 thisdate=Sep  2 2022 GMT
name
 thisdate=Sep 15 2022 GMT
1
  • Thank you! That worked perfectly for what I needed! Commented Apr 13, 2020 at 21:21

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.