I am trying to run the following command of sed
:
echo "fOO:paSS,tesT2:fail,TESt:pasS,fdfdhfd:pass,test5:anyresult test,test6:pass asfas " | sed 's/:.*/L&/;s/w+/u&/g;s/:/ # /g;y/,/n/' | sed 's/w+/&n/2;P;d'
The output which I am getting is :
FOO # Pass
TesT2 # Fail
Test # Pass
Fdfdhfd # Pass
Test5 # Anyresult
Test6 # Pass
Desired Output :
fOO # Pass
tesT2 # Fail
TESt # Pass
fdfdhfd # Pass
test5 # anyresult
test6 # Pass
What I want is :
- "Pass" & "fail" should always have "
P
" & "F
" capital, no matter whatever input is given. - Name of the "Test" should remain same as provided in echo command , it should not get changed.
- After and before of
#
there should be only first word present. If user gives input like "Test5:Pass successfully" then successfully should not get printed.
Optional requirement:
- Can we convert this to a table anyhow of 2 columns and ‘n’ rows?
2
Answers
I can’t help but think this must be a lot easier with Awk.
Using
sed
,tr
, andcut
to match the described spec of what theoutput should be, (rather than the inconsistent desired output in
the OP):
Output:
Two column variant output:
Output: