To get or print specific value in result


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To get or print specific value in result
# 1  
Old 02-03-2018
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
Code:
cat FILE | grep 'Test failed' | awk -F',' '{print $3,$8,$12}'


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

# 2  
Old 02-03-2018
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?
Code:
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


Last edited by RudiC; 02-03-2018 at 04:18 PM.. Reason: improved phrasing
# 3  
Old 02-03-2018
[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?
[CODE]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[/ICODE]

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

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

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


Last edited by mirwasim; 02-03-2018 at 03:02 PM..
# 4  
Old 02-03-2018
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:
Code:
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!
# 5  
Old 02-04-2018
Quote:
Originally Posted by Don Cragun
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:
Code:
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
# 6  
Old 02-04-2018
Ah. Thank you. Finally a specification for the part of the URL that you want...
Code:
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:
Code:
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.
This User Gave Thanks to Don Cragun For This Post:
# 7  
Old 02-04-2018
Quote:
Originally Posted by Don Cragun
Ah. Thank you. Finally a specification for the part of the URL that you want...
Code:
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:
Code:
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

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Print result of mv -n

I am trying to move files which donot have same filename using find /Users/ParijatMac/desktop/unix/new_dir -type f -mmin +"$HRS" -exec mv -n "{}" /Users/ParijatMac/desktop/unix/old_dir \; -print but i am getting all filenames including the ones with duplicate names.Please help me to sort... (5 Replies)
Discussion started by: parijat guh
5 Replies

2. Shell Programming and Scripting

Print if found non-desired result

I have a result like this root@server # grep -rl maldet /etc/cron* /etc/cron.d/maldet_daily /etc/cron.d/malcron /etc/cron.d/malcrondaily /etc/cron.d/malcronweekly What I need is, I need an if/else condition such that, if there is any output other than /etc/cron.d/maldet_daily in the... (8 Replies)
Discussion started by: anil510
8 Replies

3. Shell Programming and Scripting

How to print multiple specific column after a specific word?

Hello.... Pls help me (and sorry my english) :) So I have a file (test.txt) with 1 long line.... for example: isgc jsfh udgf osff 8462 error iwzr 653 idchisfb isfbisfb sihfjfeb isfhsi gcz eifh How to print after the "error" word the 2nd 4th 5th and 7th word?? output well be: 653 isfbisfb... (2 Replies)
Discussion started by: marvinandco
2 Replies

4. Shell Programming and Scripting

How to print with awk specific field different from specific character?

Hello, i need help with awk. I have this file: cat number DirB port 67 er_enc_out 0 er_bad_os 0 DirB port 71 er_enc_out 56 er_bad_os 0 DirB port 74 er_enc_out 0 er_bad_os 0 DirB port 75 ... (4 Replies)
Discussion started by: elilmal
4 Replies

5. UNIX for Dummies Questions & Answers

How to Detect Specific Pattern and Print the Specific String after It?

I'm still beginner and maybe someone can help me. I have this input: the great warrior a, b, c and what i want to know is, with awk, how can i detect the string with 'warrior' string on it and print the a, b, and c seperately, become like this : Warrior Type a b c Im still very... (3 Replies)
Discussion started by: radynaraya
3 Replies

6. Shell Programming and Scripting

Shifting result of echo by specific amount

I am using echo "HELLO" I want to specify a number shiftWt so that I move hello forward by shiftWt charcaters. Is there a way to do this? (2 Replies)
Discussion started by: kristinu
2 Replies

7. Shell Programming and Scripting

Print Specific lines when found specific character

Hello all, I have thousand file input like this: file1: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$ | | | |$$ $$ UERT | TTYH | TAFE | FRFG |$$ $$______|______|________|______|$$ $$ | | | |$$ $$ 1 | DISK | TR1311 | 1 |$$ $$ 1 |... (4 Replies)
Discussion started by: attila
4 Replies

8. Shell Programming and Scripting

print first few lines, then apply regex on a specific column to print results.

abc.dat tty cpu tin tout us sy wt id 0 0 7 3 19 71 extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.0 133.2 0.0 682.9 0.0 1.0 0.0 7.2 0 79 c1t0d0 0.2 180.4 0.1 5471.2 3.0 2.8 16.4 15.6 15 52 aaaaaa1-xx I want to skip first 5 line... (4 Replies)
Discussion started by: kchinnam
4 Replies

9. Shell Programming and Scripting

print out result from data file

i got a data file which contains all the pid,ppid,user,command,pcpu,start_time,status. I wanted to display out the pcpu which is greater than 0. i uses awk'{if($5 > 0){print}}' filename.txt but is printing out result which not i wanted. Is there any way which i can print out those pcpu which is... (8 Replies)
Discussion started by: thms_sum
8 Replies

10. Shell Programming and Scripting

print a function result in new file

Hi, i have a function which return a variable . serach ( paramatere) when i excute this function i get the result in the shell, i want to print this result in a file by calling just the function. how can i do it.. the code example is like that: search ( ) { .. } the call... (0 Replies)
Discussion started by: kamel.seg
0 Replies
Login or Register to Ask a Question