Alex Sim
Alex Sim

Reputation: 423

Bash: sed/grep between patterns (including only first pattern)

I want to extract all substrings starting with "[A-Z]:" and ending with "[A-Z]:" or the end of the string

so that if my input is

C:\Users\Alex Sim\Libraries\Some Folder D:\Hello world\Something C:\Ran out of names\whatever

my output would be

C:\Users\Alex Sim\Libraries\Some Folder
D:\Hello world\Something
C:\Ran out of names\whatever

Upvotes: 0

Views: 29

Answers (1)

RomanPerekhrest
RomanPerekhrest

Reputation: 92854

Simply with GNU sed:

sed 's/[[:space:]]\([A-Z]:\)/\n\1/g' input.txt

The output:

C:\Users\Alex Sim\Libraries\Some Folder
D:\Hello world\Something
C:\Ran out of names\whatever

Upvotes: 1

Related Questions