- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- awk help "colllapsing" a file
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
03-11-2013 11:27 AM
03-11-2013 11:27 AM
All:
I have the following file:
c129t11d6 SYMM 68 27cd 70.7098
c130t11d6 SYMM 68 27cd 70.7098
c142t2d5 SYMM 68 27cd 70.7098
c143t2d5 SYMM 68 27cd 70.7098
c129t11d7 SYMM 68 27d1 70.7098
c130t11d7 SYMM 68 27d1 70.7098
c142t2d6 SYMM 68 27d1 70.7098
c143t2d6 SYMM 68 27d1 70.7098
c129t12d0 SYMM 68 27d5 70.7098
c130t12d0 SYMM 68 27d5 70.7098
c142t2d7 SYMM 68 27d5 70.7098
c143t2d7 SYMM 68 27d5 70.7098
c129t12d1 SYMM 68 27d9 70.7098
c130t12d1 SYMM 68 27d9 70.7098
c142t3d0 SYMM 68 27d9 70.7098
c143t3d0 SYMM 68 27d9 70.7098
c129t12d2 SYMM 68 27dd 70.7098
c130t12d2 SYMM 68 27dd 70.7098
c142t3d1 SYMM 68 27dd 70.7098
c143t3d1 SYMM 68 27dd 70.7098
I would like to combine 4 lines into 1 line based on the 3rd field. I think you can do it with "join" in HP-UX. I know somebody can do it in "awk". Can you tell me how, please?
Stuart
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2013 11:32 AM
03-11-2013 11:32 AM
Re: awk help "colllapsing" a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2013 12:47 PM
03-11-2013 12:47 PM
Re: awk help "collapsing" a file
>I would like to combine 4 lines into 1 line based on the 4th field.
How do you want to join them? Just put them all on one line in some random order?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2013 12:51 PM
03-11-2013 12:51 PM
Re: awk help "collapsing" a file
any old way is fine. It's the compare and collapse that I'm looking for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2013 01:10 PM
03-11-2013 01:10 PM
Re: awk help "collapsing" a file
>It's the compare and collapse that I'm looking for.
If the file is already sorted on the 4th field and there are always 4 of them, you can do:
awk '
{
getline line2
getline line3
getline line4
print $0, line2, line3, line4
}' input-file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2013 01:28 PM
03-11-2013 01:28 PM
Re: awk help "collapsing" a file
>It's the compare and collapse that I'm looking for.
You can also try paste:
paste -s -d' \n' input-file
- Tags:
- paste
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2013 07:55 AM
03-12-2013 07:55 AM
Re: awk help "collapsing" a file
In this case the data came in 4-line groups, but not always.
What I was looking for was:
1. Verify that field 4 in the current record is the same as the previous record.
o combine the records
2. If field 4 is different, then write out all the previous field 4 key records (one record)
o start concatenating again.
etc...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2013 02:35 PM
03-12-2013 02:35 PM
Solution>In this case the data came in 4-line groups, but not always.
Looks like you have the algorithm down. ;-)
awk <<EOF '
BEGIN { key = ""; save = "" }
{
if ($4 != key) { # Combine on column 4
if (save != "") print save
key = $4
save = $0
next
}
save = save " " $0
}
END {
if (save != "") print save
}' input-file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2013 05:57 AM
03-13-2013 05:57 AM
Re: awk help "collapsing" a file
Cool! Thanks!
Stuart
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2013 12:36 PM
03-13-2013 12:36 PM
Re: awk help "collapsing" a file
>Cool! Thanks!
If you are happy with the answer, please also click on the Kudos stars for each helpful post.