- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk query (merge field info)
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2012 02:42 AM - last edited on 11-26-2012 07:00 PM by Maiko-I
11-26-2012 02:42 AM - last edited on 11-26-2012 07:00 PM by Maiko-I
Morning All,
I am trying to extract particular information from a file with multiple fields. The file appears like so.
cat file
gust0101:dmtc:dmtcvg00:497664:1024:32:13
gust0101:wmsc:wmscvg00:847168:64:32:32
gust0101:dmtc:dmtcvg01:470016:1024:32:10
gust0101:wmsc:wmscvg01:361088:64:32:13
gust0102:ap5c:ap5cvg00:69440:64:16:1
gust0103:dp1c:dp1cvg00:55552:64:32:1
gust0104:dp2c:dp2cvg00:345600:512:32:5
gust0201:ss4c:ss4cvg00:707328:256:32:14
gust0201:ss4c:ss4cvg06:262656:128:32:19
gust0201:ss4c:ss4cvg01:2426880:1024:128:43
gust0201:ss4c:ss4cvg02:889344:256:128:16
gust0201:ss4c:ss4cvg03:262656:128:128:19
gust0201:ss4c:ss4cvg04:262656:128:128:19
gust0201:ss4c:ss4cvg05:262656:128:128:19
I would like to scan the file and print out the non duplicates in filed 1, and append the second field that matches the first on the same line.
I.E gust0201 has 7 records so the following will be printed. along with all of the other lnes.
gust0201, ss4cvg00 ,ss4cvg01, ss4cvg02, ss4cvg03, ss4cvg04, ss4cvg05
any advice will be welcome.
thanks
P.S. This thread has been moved from HP-UX > General to HP-UX > languages - HP Forums Moderator
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2012 03:04 AM - edited 11-26-2012 03:06 AM
11-26-2012 03:04 AM - edited 11-26-2012 03:06 AM
Solution>append the second field
Looks like the third field.
If the file is sorted on field1, then you could do:
awk -F: '
BEGIN { prev = ""; save="" }
{
if ($1 != prev) { # diff key
if (save != "") {
print save
}
prev = $1
save = $1 "," $3
next
}
save = save "," $3 # same key
}
END { if (save != "") print save }' input-file
- Tags:
- awk