I have a file with lines similar to the one below, and I want to replace all things between the “steps” and “-” with a new line:
- name: Change It uid: Change It_TRANS_App - Web type: TRANSACTION steps: 02 - name: Change It 1 type: BSTEP uid: Step 1_STEP_Change It_TRANS_App -strong text Web rules:
I tried using awk like:
echo $string | awk {'gsub(/steps:.*?-/ , 'steps:\n-' )'; print $0}
However, I get the following error:
awk: {gsub(/steps:.*?-/ , steps:n- )
awk: ^ syntax error
awk: fatal: 0 is invalid as number of arguments for gsub
I also tried with sed:
sed -r 's:/\bsteps:\b.*?-/\n/' stringfile.txt > output.txt
and deleting ":":
sed -r 's/\bsteps.*?-/\n/' stringfile.txt > output.txt
In the first case, I get an error:
sed: -e expression
And with the second sed, I delete many other things that it should not do.
[Edit] As you guys told me, I forgot to deliver the expected result, I thought it would be easy, but I'm not good. I want to break because the new line only cuts out the word immediately after the "step", in this case it will be "02". This will be the first appearance of a "-":
- name: Change It uid: Change It_TRANS_App - Web type: TRANSACTION steps:
- name: Change It 1 type: BSTEP uid: Step 1_STEP_Change It_TRANS_App -strong text Web rules: