0

I have a file.txt that contains these lines: (the actual dates will vary, but are always in this format)

UPDATE_FILE: filename.update
TEST_DATE: Sun Aug 30 10:22:32 MDT 2020
DATE: Sun Aug 30 13:21:44 MDT 2020

I am currently using this line to parse the file and return the UPDATE_FILE name:

$ sed -n -e '/UPDATE_FILE/{s/.*: *//p}' file.txt
file.update

However, I have issues when using it on the other line, probably because I set the deliminater to a colon.

sed -n -e '/TEST_DATE/{s/.*: *//p}' file.txt returns:

$ sed -n -e '/TEST_DATE/{s/.*: *//p}' test.txt
32 MDT 2020

How do I return the entire line following the FIRST colon following the "keyword"? Such as: (assuming the sed is correct)

$ sed -n -e '/TEST_DATE/{s/.*: *//p}' test.txt
Sun Aug 30 10:22:32 MDT 2020
Ebad
  • 131
  • 11

2 Answers2

0

In this special case there is no need for sed or regex:

while IFS=': ' read -r a b
do 
   echo "${b}"
done < file.txt
Marco
  • 824
  • 9
  • 13
0
$ sed -n 's/^UPDATE_FILE: //p' file
filename.update

$ sed -n 's/^TEST_DATE: //p' file
Sun Aug 30 10:22:32 MDT 2020

$ sed -n 's/^DATE: //p' file
Sun Aug 30 13:21:44 MDT 2020
Ed Morton
  • 188,023
  • 17
  • 78
  • 185