ffmj0010.09o:FFMJ MARKER NAME
ffmj0020.09o:BRMU MARKER NAME
In this text file (2 lines and no space between the lines) I need to extract 4 characters after ":" ("FFMJ", "BRMU") and save them in another text file. Which command do I need to use?
Using
sed
:s
: asserts to perform a substitution/
: stops the command / starts the pattern.*:
: matches any number of any character until the last:
character and a:
character\(.\{4\}\)
: matches and groups 4 occurences of any character.*
: matches any number of any character/
: stops the pattern / starts the replacement string\1
: backreference replaced with the first captured group/
: stops the replacement string / starts the pattern flagsSample output on the example file:
If you are sure that you want exactly 4 characters before end of the line, you can do:
Otherwise you can go for
grep
with PCRE to get all characters after:
till the end of the line:You can also use
bash
parameter expansion:EDIT:
As @kos pointed out I might have misunderstood the question, if you want exactly 4 characters after
:
you can do:Using
awk
and multiple delimitersExample
Using
grep
:Then the
> newFile
outputs to a file.On the example:
goes to