Issue
I have a text file which contains bunch of strings as shown below.
-V -am line+tgl -am assert -debug+all -zdb -fcs_assert off
I want to search for string starting with pattern '-' and check if the next word starts with '-'. If it does then move it to next line, else keep it in the same line.
Expected output:
-V
-am sqr+tgl
-am assert
-debug+all
-zdb
-fcs_assert off
I tried replacing space with next line character and lines which don't start with '-' append it to previous line. I am unable to figure out the second half of this approach.
cat ins.tmp/cmd.vcs | sed 's/ /\n/g'
Solution
You may use this awk
solution:
awk -F ' +-' -v OFS='\n-' '{$1=$1} 1' file
-V
-am line+tgl
-am assert
-debug+all
-zdb
-fcs_assert off
Answered By - anubhava Answer Checked By - Cary Denson (WPSolving Admin)