UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 13th, 2003, 01:43 PM
steve1374 steve1374 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 2 steve1374 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question on script using awk

2131100 COVS/100C E|FWP AREAS|MIDWEST|
2131100 COVS/100C E|FWP AREAS|CONSTRUCTION|
2131100 COVS/100C E|FWP AREAS|FTC|
2131100 COVS/100C E|FWP AREAS|FWP AREAS|
2131100 COVS/100C E|FWP AREAS|CLEANING|
2131100 COVS/100C E|FWP AREAS|FCRE|
2131200 COVS/100C UPS|UPS ROOMS|CONSTRUCTION|
2131200 COVS/100C UPS|UPS ROOMS|UPS ROOMS|
2131200 COVS/100C UPS|UPS ROOMS|FCRE|
2131200 COVS/100C UPS|UPS ROOMS|EMERGENCY|

I am running a report that produces the output shown above. I am trying to use awk in the script to format the output to look like this

2131100 COVS/100C E|FWP AREAS|MIDWEST|CONSTRUCTION|FTC|FWP AREAS|CLEANING|FCRE|

All information would be on one line but the carriage return was forced when typing into the area for this post.
Basically, I want to keep only the first occurence of the information in colums 1 and 2. I then want to list the information in column 3 from left to right in the same row. I want to do this for each new number listed, ie: one row that looks like the example above for 2131100 another row for 2131200 etc...

Attached below is a copy of the AWK script which does not seem to be working properly.

Any insight on how to accomplish this would be greatly appreciated.

awk -F"|" 'BEGIN {SS_A=""}
{if (NR==1)
{SS_A=$1; printf $0}
else
{if (SS_A==$1)
{printf "|"$2}
else
{SS_A=$1;
printf "\n"$0}
}
} END {printf "\n"}' $SF_OUT

Reply With Quote
  #2  
Old February 20th, 2003, 09:49 AM
zakj zakj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 52 zakj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 41 sec
Reputation Power: 6
The following works for me:

Code:
#!/usr/bin/awk -f

BEGIN {
  FS="|"
  line=""
}

$1 $2 == line {
  printf $3 FS
  next
}

{
  if (line != "")
    print ""
  printf $0
  line=$1 $2
}

END {
  print ""
}

Reply With Quote
  #3  
Old March 18th, 2003, 01:28 PM
steve1374 steve1374 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 2 steve1374 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
reply to awk code

thank you for the response. Any idea why the script suggested would be producing output that contains 2 occurences of the 2nd field?

Any thoughts are welcome. Also, if an example of input and/or output would be helpful I can provide them.

Thank you.

Reply With Quote
  #4  
Old March 22nd, 2003, 10:18 PM
zakj zakj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 52 zakj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 41 sec
Reputation Power: 6
Please do provide an example of the input you used that caused a problem, as well as the output you saw. The output I get from the example input you posted originally is:
Quote:
2131100&nbsp;COVS/100C&nbsp;E|FWP&nbsp;AREAS|MIDWEST|CONSTRUCTION|FTC|FWP&nbsp;AREAS|CLEANING|FCRE|
2131200&nbsp;COVS/100C&nbsp;UPS|UPS&nbsp;ROOMS|CONSTRUCTION|UPS&nbsp;ROOMS|FCRE|EMERGENCY|

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Question on script using awk


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway