Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk processing.... 1

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
PL

hello

the input file has lines:

Code:
N750:156#x5#(none)#0#/0#0##1#100
N850:154#x5#(none)#2#/0#0##1#100
N770:152#x5#(none)#0#/0#3##1#200
N760:155#x5#(none)#0#/5#0##1#200

expected output is:
Code:
N750 0 100 N850 2 100
N770 0 200 N760 0 200

How to modify my command (to be easiest as possible and shortest - even rid off the "for" loop) to get expected output?

Code:
for i in `awk -F\# '$2 == "x5" {print $NF}' input|sort -u`;do awk -F\# -va=$i '$NF == a {print $1" "$4" "a}' input|awk 'ORS=NR%2?" ":RS';done

Now it produces:

Code:
N750:156 0 100 N850:154 2 100
N770:152 0 200 N760:155 0 200
 
Something like this ?
Code:
sort -t'#' -k9 input | awk -F'#' '$2=="x5"{
if($9!=a){if(NR>1&&nr%2==1)printf "\n";a=$9;nr=0}
++nr;ORS=nr%2?" ":RS;sub(/:.*/,"",$1);print $1" "$4" "$9}
END{if(nr%2==1)printf "\n"}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top