I have tried using awk and cut, bu the position of these values keep changing, so I can use awk and split it into columns.
The value before the ":' is always constant, the value in the brackets only keep changing.
I need an option which prints in the following manner based on what is being grepped.
it should be a one liner and it should be able to compare the value in the brackets for "xyz:" and "abz:" and if it is the samee then it should print "qrt: [2312]"
In the above lines the output should be only "qrt: [2312]" as that is the only line with the matching value in the bracket of "xyz:" and "abz:".
The positions of this variable keep changing in the same line, so I cannot use the divide by columns.
I'm curious: why should it be a one-liner? Is there some length limit? Because, technically, you can convert any large, multi-line awk script into a one liner by simply deleting the newline bytes.
What should the script output if qrt: does not match the other two? Are these abc: xyz: qrt: values input parameters or hard-coded into script? Can you should some example input, script parameters and required output?
this condition is part of a much larger script, Initially I have used the following condition, bu there have been changes int he file format where the values are not specific to a column, so this is not working.
awk '$2!=$5{print $9}'
I hope this info helps.
Thanks
---------- Post updated 02-28-13 at 12:51 PM ---------- Previous update was 02-27-13 at 01:40 PM ----------
can some one please help me with the second question?
awk 'NR==1 {n = split (items, IT)} # put the items to search for into array IT
{for (i=1; i<NF; i++) # check every single field in actual line
for (j=1; j<=n; j++) # against the items wanted
if ($i == IT[j]) VL[j]=$(++i) # if found, register value (= next field) in array VL, and skip check on value
}
VL[1]==VL[2] {print VL[3]} # if values of first two items match, print value of third
' items="xyz: abz: qrt:" file
[2312]
I need a one liner because it is part of a bigger script as I have mentioned. I am not sure what do you mean by homework. I am writing this script to gather a lot of different variables, and this is just one of the variable.
A solution and the number of lines in the code is also equally important to me as I will be filtering a lot of other parameters before i come to this part of comparison, and also do a lot more filtering and calculation.
Earlier when the position of the variables in the log files weren't changing so i used to use a simple awk comparison like below,
awk '$2!=$5{print $9}'
I am not an expert in awk, so I am asking help on this.
And finally sorry for starting another thread, I wasn't sure if it has to be one question in each thread, so I started a new one.
Most of the time, I search and try for solutions from the existing threads, but i couldn't find anything close to my problem and I really need some help in getting this solution.
then the output should be null, as I want the comparison of the value in the bracket of only xyz and abz. and print qrt only if it is the same.
In your example the values in the brackets of xyz and abz are not equal so, it should not return anything
The solution offered above works perfectly on all examples you provided so far. Put it into a function if you aim for readability of the main script.
BTW, even if sensibly (!) collapsed to a one liner, it will work ...