To get a single string in output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To get a single string in output
# 1  
Old 01-30-2018
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)
Code:
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


Code:
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

Code:
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

# 2  
Old 01-30-2018
Using sed:-
Code:
sed 's#,[^/]*/#,#;s#/##' file

# 3  
Old 01-30-2018
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:-
Code:
while IFS="/," read f1 f2 f3 f4 f5
do
   echo "${f1},${f3},${f5}
done < ERROR_FILE.log


The output for me is:-
Code:
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

Last edited by rbatte1; 01-30-2018 at 11:26 AM.. Reason: Caviat about performance.
# 4  
Old 01-30-2018
Quote:
Originally Posted by Yoda
Using sed:-
Code:
sed 's#,[^/]*/#,#;s#/##' file


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 ----------

Quote:
Originally Posted by rbatte1
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:-
Code:
while IFS="/," read f1 f2 f3 f4 f5
do
   echo "${f1},${f3},${f5}
done < ERROR_FILE.log


The output for me is:-
Code:
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
# 5  
Old 01-30-2018
Just need to use the same regex in nawk:-
Code:
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

# 6  
Old 01-30-2018
Quote:
Originally Posted by Yoda
Just need to use the same regex in nawk:-
Code:
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

Code:
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 ----------

Quote:
Originally Posted by Yoda
Using sed:-
Code:
sed 's#,[^/]*/#,#;s#/##' file

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

Code:
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

# 7  
Old 01-30-2018
Ok, escape it:-
Code:
sub ( /[^\/]*\//, X, $i )

This User Gave Thanks to Yoda For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Single grep to multiple strings with separate output per string

I need to grep multiple strings from a particular file. I found the use of egrep "String1|String2|String3" file.txt | wc-l Now what I'm really after is that I need to separate word count per each string found. I am trying to keep it to use the grep only 1 time. Can you guys help ? ... (9 Replies)
Discussion started by: nms
9 Replies

2. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

3. Shell Programming and Scripting

Output to single line

Hi, I am using below command and getting below output. echo "dis ql(*) CLUSTER"|runmqsc CT.QM.ASSA10T1| egrep 'QUEUE|CLUSTER'|egrep -v 'SYSTEM|XMITQ'| sed -e 's/QUEUE(/ /g' -e 's/TYPE(QLOCAL)/ /g' -e 's/CLUSTER(/ /g' -e 's/)/ /g' output CT.CL.ALLUHUB.FLST_TO_HUB_PROV.01... (20 Replies)
Discussion started by: darling
20 Replies

4. Shell Programming and Scripting

Output to be in single line

Hi All, Small script but :wall:, please help in this regard. for i in 1 2 3 do echo $i done result : 1 2 3 I want the above to be printed as below expected result: 1 2 3 Thanks in advance :) (3 Replies)
Discussion started by: girish_satyam
3 Replies

5. Shell Programming and Scripting

How to select a single string

I am learning sed/awk. So, bear with me. I have successfully created a list (based on sed) which looks like: <cl:item href="clsysrev/XTT004/XTT05064.xml" productSubtitle="animals" unitStatus="today"IR"> <cl:item href="clsysrev/XTT007/XTT08581.xml" productSubtitle="humans"... (3 Replies)
Discussion started by: alonso_canada
3 Replies

6. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

7. Shell Programming and Scripting

awk: round output or delimit output of arithmatic string

I have a file with the following content. > cat /tmp/internetusage.txt 6709.296322 30000 2/7/2010 0.00I am using the following awk command to calculate a percentage from field 1 and 2 from the file. awk '{ print $1/$2*100 }' /tmp/internetusage.txt This outputs the value "22.3643" as a... (1 Reply)
Discussion started by: jelloir
1 Replies

8. Shell Programming and Scripting

How to print the output in single line

Hi, Please suggest, how to get the output of below script in single line, its giving me in different lines ______________________ #!/bin/ksh export Path="/abc/def/ghi"; Home="/home/psingh/prat"; cd $Path; find $Path -name "*.C#*" -newer "abc.C#1234" -print > $Home cat $Home | while... (1 Reply)
Discussion started by: Prat007
1 Replies

9. AIX

ls command output in single line

Hi, Can anyone suggest me how can I display the output of ls command in single line with some delimiter say pipe (|)? I know it can be done by writing a script by using the loops but I wanted to know are there any other single line commands? Thanks for your help Sheshadri (7 Replies)
Discussion started by: arsheshadri
7 Replies

10. Shell Programming and Scripting

Need output in different lines not in one single line

I am getting the coutput like this as show below in one single line, where as the command is executed is several lines and the output should also be requied in several lines, not in one single line. Anyone any idea? p4 opened -a | grep *locked* | awk '{ printf $8 }' >/tmp/aa $ cat... (1 Reply)
Discussion started by: csaha
1 Replies
Login or Register to Ask a Question

Featured Tech Videos