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

Status
Not open for further replies.

grapes12

Technical User
Mar 2, 2010
124
ZA
awk command displays duplicates
Code:
awk 'BEGIN {while ( getline < "sun5-printers.txt") {arr[$0]++ } } { if (!($0 in a
rr ) ) { print } }' sun8-printers.txt > diffs.txt

or is it my do command:
Code:
for i in `cat diffs.txt`
do
   printer="$(awk -F: '{print $1}' | cut -c11-18 diffs.txt)"
   echo $printer
done

herewith is the output run with ksh -x:
Code:
+ cat diffs.txt
+ + cut -c11-18 diffs.txt
+ awk -F: {print $1}
printer= 0117bd1
 2201bl7
 5001bl1
+ echo 0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1
+ + cut -c11-18 diffs.txt
+ awk -F: {print $1}
printer= 0117bd1
 2201bl7
 5001bl1
+ echo 0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1
+ + cut -c11-18 diffs.txt
+ awk -F: {print $1}
printer= 0117bd1
 2201bl7
 5001bl1
+ echo 0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1




 
I resolved the problem.
removed the for i statement
and only used the
printer_list as a variable
Code:
printer_list="$(awk -F: '{print $1}' diffs.txt | cut -c11-18)"
echo $printer

No-more duplicates
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top