Using Raku (formerly known as Perl_6)
Assuming lines-to-be-modified all contain at least 4 whitespace-separated "columns" (lines with fewer than 4 "columns" are returned unmodified):
raku -ne 'my @a = .words; @a.elems >= 4 ?? put @a[0..1], "\n", @a[2..*] !! put @a;'
Above assumes no string pattern in the input, only the appropriate number of whitespace-separated words
(i.e. columns). For matching lines, the first 2 columns are returned, then a newline, then the remaining columns (the OP provides Sample Input wherein the string job_type
begins the 3rd column).
However, if you want to use a regex and search for string patterns, Raku has your back (using the subst
operator). Below, Raku searches for 8 regex atoms between / ^ ... $ /
, between the ^
start-of-string and $
end-of-string zero-width assertions (anchors). Once matched, Raku's <(
capture marker is used to drop everything before job_type
from the match. Then in the subst
replacement half, a \n
newline is ~
concatenated to the $/
match-variable and returned.
raku -ne '.subst(/^ insert_job\: \s .+? \s <(job_type\: \s \w* \s*? $/, {"\n"~$/} ).put;'
Sample Input:
insert_job: VAU_vaultnotification_ertgvfg_job job_type: xxx
insert_job: VAU_vaultnotification_ertgvfg_frd job_type: yyy
insert_job: VAU_vaultnotification_ertgvfg_erb job_type: SXC
job_type: CMD
insert_job: VAU_vaultnotification_ertgvfg_frd job_type: YUI
Sample Output (first code example, above):
insert_job: VAU_vaultnotification_ertgvfg_job
job_type: xxx
insert_job: VAU_vaultnotification_ertgvfg_frd
job_type: yyy
insert_job: VAU_vaultnotification_ertgvfg_erb
job_type: SXC
job_type: CMD
insert_job: VAU_vaultnotification_ertgvfg_frd
job_type: YUI
Note, the OP hasn't made clear if all output should be left-justified or not (zero leading-whitespace characters). The first answer above is left-justified, however it's easy to trim
or even indent all lines that start with job_type
in the output (for example, in the second answer using {"\n "~$/}
in the replacement will indent).
https://raku.org
abcdjob_type
be a match? Can you include some cases that should not be changed? How does thesed
command fail? Does it not run? Does it run but do the wrong thing? Please edit your question and clarify.