Search code examples
linuxunixsedgrepcygwin

how to print remaining portion of each line after a pattern match using sed


I have the following text in my file.

log-2023-06-30-082821.txt:2023-06-30 08:30:32.648
log-2023-06-30-082821.txt:2023-06-30 08:32:07.235
log-2023-06-30-083220.txt:2023-06-30 08:32:55.831
log-2023-06-30-083604.txt:2023-06-30 08:36:39.380

I want to print the rest of the portion of each line as soon as there is a pattern match ':'. The output should look like this.

2023-06-30 08:30:32.648
2023-06-30 08:32:07.235
2023-06-30 08:32:55.831
2023-06-30 08:36:39.380

How can I do this using sed. I am using Cygwin in Windows. I tried a bunch of sed patterns but they haven't worked.


Solution

  • For a single character, you can use it as a field separator with cut and display except the first field. For example:

    $ echo 'log-2023-06-30-082821.txt:2023-06-30 08:30:32.648' | cut -d: -f2-
    2023-06-30 08:30:32.648
    

    You can also delete up to the first : character using sed 's/^[^:]*://'