I have a file that reads similar to this:
random_string
83: some words 45: large error report 326: send emails to certain peple
random_string
34: some words 143: job success
I want to target the pattern "#:" (a number followed by a colon) and add a new line after the text that follows it; so it reads like this:
random_string
83: some words
45: large error report
326: email certain people
random_string
34: some words
143: job success
I've tried a sed commands of:
sed "s#'([0-9]*[0-9]:)'#a '/n'#" file.txt
sed "s#'([0-9]*[0-9]:)'#\n#g" file.txt
(I don't like using slashes as delimiters, the fence posts make it hard to read)
and an awk command of:
awk '/[0-9]*[0-9]:/ {printf "%s\n",$0}' file.txt
And neither have worked. I've looked at similar problems posted here and tried their solutions but nothing has worked. I know the answer is most likely very similar and it may even have something to do with the syntax in my number expression but I can't figure it out myself. I have no preference to either awk or sed but I think they would be the best tools at my disposal.
Help?
FILENAME
as the first line? There's only oneFILENAME
in your input. And how can we know where the filename (if that's what it is) ends? For instance,83: xyz
has a space after thexyz
, is that part of the name or should it be removed? Can the file name have numbers in it?