To get a single string in output

I am looking forward to achive below expecrted result, but when I am trying i could now get the whole string between two / / what I am getting is the last word
i need to take complete line which is between / / ignore the line after , and before / which is (Test failed: text expected not to contain)

File input 

SKILLED LANGUAGE - ENTER CREDENTIALS,Test failed: text expected not to contain /You do not have skills or languages/,http://abc:1234/new.xhtml
BILLING - ONLINE BILL DETAILS 3,Test failed: text expected not to contain /FETCH_ONLINE_CURRENT_BILL_DETAILS/,http://abc:1234/new.xhtml
BILLING - ONLINE BILL DETAILS 4,Test failed: text expected not to contain /FETCH_ONLINE_PREVIOUS_BILL_DETAILS/,http://abc:1234/new.xhtml
INTERACTION - SUB ORDERS - VIEW - MANAGED SERVICE 3,Test failed: text expected not to contain /UN_HANDLED_EXCEPTION/,http://abc:1234/new.xhtml
expected out put 

SKILLED LANGUAGE - ENTER CREDENTIALS,You do not have skills or languages,http://abc:1234/new.xhtml
BILLING - ONLINE BILL DETAILS 3,FETCH_ONLINE_CURRENT_BILL_DETAILS,http://abc:1234/new.xhtml
BILLING - ONLINE BILL DETAILS 4, FETCH_ONLINE_PREVIOUS_BILL_DETAILS,http://abc:1234/new.xhtml
INTERACTION - SUB ORDERS - VIEW - MANAGED SERVICE 3,UN_HANDLED_EXCEPTION,http://abc:1234/new.xhtml
script I am using

nawk 'BEGIN{print "<table border="1">"}
       {print "<tr>";
       print "<TD>";
       for(i=1;i<NF;i++) printf("%s ",  $i);
       print "</TD>";
       print "<TD>" $NF "</TD>";
       print "</tr>"}
     END{print "</table>"}'  ERROR_FILE.log 

Using sed:-

sed 's#,[^/]*/#,#;s#/##' file

I'm not very good with awk/nawk, but do you not need to set the field separator with the -F flag. It might be complicated because you have two delimiters or which one is / and also used in the literal text. The other being ,

If it was in bash I would write something like:-

while IFS="/," read f1 f2 f3 f4 f5
do
   echo "${f1},${f3},${f5}
done < ERROR_FILE.log

The output for me is:-

SKILLED LANGUAGE - ENTER CREDENTIALS,You do not have skills or languages,http://abc:1234/new.xhtml
BILLING - ONLINE BILL DETAILS 3,FETCH_ONLINE_CURRENT_BILL_DETAILS,http://abc:1234/new.xhtml
BILLING - ONLINE BILL DETAILS 4,FETCH_ONLINE_PREVIOUS_BILL_DETAILS,http://abc:1234/new.xhtml
INTERACTION - SUB ORDERS - VIEW - MANAGED SERVICE 3,UN_HANDLED_EXCEPTION,http://abc:1234/new.xhtml

With a large file, the performance could be much slower than an awk or perhaps sed

I hope that this helps,
Robin

thanks for your feedback ,but i will need in awk as i need the output to send in email in same script how i mentioned above.
any modification in above script will be appreciated

---------- Post updated at 09:16 PM ---------- Previous update was at 09:15 PM ----------

thanks for your feedback ,but i will need in awk as i need the output to send in email in same script how i mentioned above.
any modification in above script will be appreciated

Just need to use the same regex in nawk:-

nawk -F, '
        BEGIN {
                print "<html>"
                print "<body>"
                print "<table border=1>"
        }
        {
                print "<tr>"
                for ( i = 1; i <= NF; i++ )
                {
                        if ( i == 2 )
                        {
                                sub ( /[^/]*\//, X, $i )
                                sub ( /\//, X, $i )
                        }
                        print "<td>" $i "</td>"
                }
                print "</tr>"
        }
        END {
                print "</table>"
                print "</body>"
                print "</html>"
        }
' file

I am getting below error

nawk: extra ] at source line 13
 context is
                                   sub ( >>>  /[^/] <<< *\//, X, $i )
nawk: nonterminated character class [^
 source line number 13

---------- Post updated at 10:13 PM ---------- Previous update was at 10:06 PM ----------

you script worked as expected by when i am running in as below the output is in single ROW, how can i get three lines in three rowS and so on

echo "<br />"  >  ,ERROR_FILE.html
echo "<html>" >>  ERROR_FILE.htm
echo "<Body>" >>  ERROR_FILE.html
sed 's#,[^/]*/#,#;s#/##'  ERROR_FILE.log >>  ERROR_FILE.html ##URLs with ports which are having error
echo "</Body>" >>  ERROR_FILE.html
echo "</html>" >>  ERROR_FILE.html

Ok, escape it:-

sub ( /[^\/]*\//, X, $i )
1 Like

Or alternatively use a regex string:

sub ( "[^/]*/", X, $i )
sub ( "/", X, $i )

Thanks Yoda,
i have added the header also to the script you provided, it is working fine, but I am expecting to get the header over those rows for which the URL or port changes. URL will remain same for few rows and then it change, and once the URL change the header should come,
like in below input you can see the 3 record URL changed.so the header should populate over the third record(validate only server and port )

INPUT FILE:
SKILLED LANGUAGE - ENTER CREDENTIALS,You do not have skills or languages,http://xxx:7003/abc/protected/home.xhtml

NOT KNOWN - NEW VALUE,You do not have skills or languages,http://xxx:7003/abc/protected/home.xhtml
SKILLED LANGUAGE - ENTER CREDENTIALS,You do not have skills or languages,http://xxx:7005/abc/protected/home.xhtml


nawk -F, '
        BEGIN {
	        print "<html>"
                print "<body>"
                print "<table border=3>"        
                                print "<tr bgcolor=#85C1E9>"
                                print "<th>FUNCATIONALITY</th>"
                                print "<th>ERROR</th>"
                                print "<th>URL</th>"
                                print "</tr>"
        }
        {
                print "<tr>"
                for ( i = 1; i <= NF; i++ )
                {
                        if ( i == 2 )
                        {
                                sub ( /[^\/]*\//, X, $i )
                                sub ( /\//, X, $i )
                        }
                        print "<td>" $i "</td>"
                }
                print "</tr>"
        }
        END {
                print "</table>"
                print "</body>"
                print "</html>"
        }
                ' filename