To get or print specific value in result

i am executing below code to achive my result, but for second row the value is not coming
it should come URL like other two . url start with http:// and end with .xhtml

cat FILE | grep 'Test failed' | awk -F',' '{print $3,$8,$12}'
INPUT
1517679173303,84,SKILLED LANGUAGE - ENTER CREDENTIALS,200,OK,Thread Group 1-1,false,Test failed: text expected not to contain /You do not have skills or languages/,1742,1,1,http://ad123:2015/see/protected/house.xhtml,84,1,1
1517679188827,30704,ACCOUNT_SERVICE + WEYANK -SEARCH,200,OK,Thread Group 1-1,false,"Test failed: text expected not to contain /Can not load Weyak Services details, Unknown error/",1928,1,1,http://ad123:2015/see/protected/Profile.xhtml,30704,1,1
1517679362169,1941,INTERACTION - SUB ORDERS - VIEW - MANAGED SERVICE 3,200,OK,Thread Group 1-1,false,Test failed: text expected not to contain /UN_HANDLED_EXCEPTION/,1857,1,1,http://ad123:2015/see/protected/meeting.xhtml,1940,1,1

Expected

skill LANGUAGE - ENTER CREDENTIALS Test failed: text expected not to contain /You do not have skills or languages/ http://ad123:2015/see/protected/house.xhtml
ACCOUNT_SERVICE + new -SEARCH "Test failed: text expected not to contain /Can not load Weyak Services details/ http://ad123:2015/see/protected/Profile.xhtml 
meeting - SUB ORDERS - VIEW - MANAGED SERVICE 3 Test failed: text expected not to contain /UN_HANDLED_EXCEPTION/ http://ad123:2015/see/protected/meeting.xhtml

The number of fields (NF) seems to be different; probably due to the comma in field 8.

And, why should the below transformations happen with your code in post#1?

INPUT                                               ---> Expected
SKILLED LANGUAGE - ENTER CREDENTIALS                ---> skill LANGUAGE - ENTER CREDENTIALS
ACCOUNT_SERVICE + WEYANK -SEARCH                    ---> ACCOUNT_SERVICE + new -SEARCH
INTERACTION - SUB ORDERS - VIEW - MANAGED SERVICE 3 ---> meeting - SUB ORDERS - VIEW - MANAGED SERVICE 3

[quote=rudic;303012398]
The number of fields (NF) seems to be different; probably due to the comma in field 8.

And, why should these transformations happen?

SKILLED LANGUAGE - ENTER CREDENTIALS ---> skill LANGUAGE - ENTER CREDENTIALS
ACCOUNT_SERVICE + WEYANK -SEARCH ---> ACCOUNT_SERVICE + new -SEARCH
INTERACTION - SUB ORDERS - VIEW - MANAGED SERVICE 3 ---> meeting - SUB ORDERS - VIEW - MANAGED SERVICE 3

Dear,
this is a live test on a website, when we click on different tabs its values changes in URL.that why the changes is seen.

my command which I am running is giving the output but in 2nd like I am getting the value for $12, actually $12 will be the URL name so is there a way with out giving field value i can print URL   that too like thishttp://ad123:2015/see/.
it will solve my header issue also
i understand the value in 2nd line is more that is why the issue, so if we can print the URL there?
Please help, Sorry to write so much but I am looking for below result from input file



ACCOUNT_SERVICE + WEYANK -SEARCH,Test failed: text expected not to contain /Can not load Weyak Services details, Unknown error/,http://ad123:2015/see/

---------- Post updated at 02:21 AM ---------- Previous update was at 12:14 AM ----------

Sorry for the confusion created, i think i have not been able to put my requirement clearly


actually command I tried to get the expected output is below but due it extra , in $8 the value is not coming properly
looking for your support to achive below


cat FILE | grep 'Test failed' | awk -F',' '{print $3,$8,$12}'

INPUT
1517679173303,84,SKILLED LANGUAGE - ENTER CREDENTIALS,200,OK,Thread Group 1-1,false,Test failed: text expected not to contain /You do not have skills or languages/,1742,1,1,http://ad123:2015/see/protected/house.xhtml,84,1,1
1517679188827,30704,ACCOUNT_SERVICE + WEYANK -SEARCH,200,OK,Thread Group 1-1,false,"Test failed: text expected not to contain /Can not load Weyak Services details, Unknown error/",1928,1,1,http://ad123:2014/see/protected/Profile.xhtml,30704,1,1
1517679362169,1941,INTERACTION - SUB ORDERS - VIEW - MANAGED SERVICE 3,200,OK,Thread Group 1-1,false,Test failed: text expected not to contain /UN_HANDLED_EXCEPTION/,1857,1,1,http://ad1234:2015/see/protected/meeting.xhtml,1940,1,1
expected
SKILLED LANGUAGE - ENTER CREDENTIALS, Test failed: text expected not to contain /You do not have skills or languages/, http://ad123:2015/see/
ACCOUNT_SERVICE + WEYANK -SEARCH, "Test failed: text expected not to contain /Can not load Weyak Services details, Unknown error/", http://ad123:2014/see/
INTERACTION - SUB ORDERS - VIEW - MANAGED SERVICE 3, Test failed: text expected not to contain /UN_HANDLED_EXCEPTION/, http://ad1234:2015/see/

If you always have the same number of fields and the last three fields do not contain commas you can replace your pipeline with just the awk command:

awk -F, '
BEGIN {OFS = ","
}
/Test failed/ {
	if(match($0, /"Test failed[^"]*"/))
		print $3, substr($0, RSTART, RLENGTH), "http://ad1234:2015/see/"
	else	print $3, $8, "http://ad1234:2015/see/"
}' FILE

Which will print the fixed URL string you have requested.

If you want the output URL to be based on a URL found in the input file, PLEASE explain what rules are to be used to convert the input URL that can be found in $(NF-3) into the string that you want to be printed instead of the entire URL!

thanks for feedback
the URL which will come as output is not static , they are dynamic so I cannot pass the specific URL name

rather of giving a URL from the file I should be able to see $3, $8 and URL (Start from http and end and see/ because those values are static and rest like server name and port change

Ah. Thank you. Finally a specification for the part of the URL that you want...

awk -F, '
BEGIN {OFS = ", "
}
/Test failed/ {
	match($(NF - 3), "http:.*/see/")
	URL = substr($(NF - 3), RSTART, RLENGTH)
	if(match($0, /"Test failed[^"]*"/))
		print $3, substr($0, RSTART, RLENGTH), URL
	else	print $3, $8, URL
}' FILE

which, with your sample input, produces the output:

SKILLED LANGUAGE - ENTER CREDENTIALS, Test failed: text expected not to contain /You do not have skills or languages/, http://ad123:2015/see/
ACCOUNT_SERVICE + WEYANK -SEARCH, "Test failed: text expected not to contain /Can not load Weyak Services details, Unknown error/", http://ad123:2014/see/
INTERACTION - SUB ORDERS - VIEW - MANAGED SERVICE 3, Test failed: text expected not to contain /UN_HANDLED_EXCEPTION/, http://ad1234:2015/see/

as requested.

If someone wants to try this on a Solaris/SunOS system, change awk in this script to /usr/xpg4/bin/awk or nawk .

I tried this but it is not working for me, i tried with nawk and it is printing all the files name available in same directory and then below error message

when i pass file name and copy paste script then below is happening

-bash-4.1$ nawk -F, '
> BEGIN {OFS = ", "
> }
> /Test failed/ {
> match($(NF - 3), "http:.*/see/")
> URL = substr($(NF - 3), RSTART, RLENGTH)
> if(match($0, /"Test failed[^"]*"/))
> 
file1  file2  file3 file4
> print $3, substr($0, RSTART, RLENGTH), URL
> elseprint $3, $8, URL
> }' file
nawk: syntax error at source line 9
 context is
        elseprint >>>  $3, <<< 
nawk: illegal statement at source line 9
-bash-4.1$ 

Do you see any difference between the code you ran above and the code I suggested below?

awk -F, '
BEGIN {OFS = ", "
}
/Test failed/ {
	match($(NF - 3), "http:.*/see/")
	URL = substr($(NF - 3), RSTART, RLENGTH)
	if(match($0, /"Test failed[^"]*"/))
		print $3, substr($0, RSTART, RLENGTH), URL
	else	print $3, $8, URL
}' FILE

None of the code marked in red matches between the two. In addition to that you have removed all of the indentation which makes the code I suggested easy to read and the code you used hard to read. In particular, on the line that generated the diagnostic, my code had a tab between else and print which is not at all compatible with the code you used with those three words changing to the two words elseprint $3 .

If you try running the code I suggested, you will probably find that it works much better than the abomination of the code I suggested that you tried running. :mad:

The only change that should have been made to the code I suggested would be to change FILE at the end of the script to the actual pathname of the file you want to process.

Respected Sir,

trust me i use same piece of code what you gave and my file name is also same
but it is not giving space in screen between else and print
no i break the line after else and it worked

If the code you paste onto your screen doesn't look like the code you copied from this site, then the code you are running is not the same piece of code that you were given.

So now you know that copying and pasting code into a shell when filename completion is enabled in that shell DOES NOT WORK. Even if filename completion is disabled, pasting multi-line code or code containing tab characters might not do what you expect depending on what options are enabled in your shell.

When sample code is suggested for you in this forum, the proper way to handle it is to copy into a file and then tell your shell to execute that file. If you use an editor to copy code into a file, be sure that auto-indentation is turned off and that your editor is set to use UNIX text file format (with each line terminated by a <newline> character; not DOS format with <carriage-return><line-feed> character pairs as line terminators).

Please close this thread

I have tagged the thread with "solved" and "awk" tags which indicate that awk was used to provide a working solution to your problem (which you could have easily done yourself).

Why do you want to close the thread now? Do you really want to forbid someone else with a better solution from adding a post to this thread with their suggestion?