- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Row to column conversion
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
04-11-2013 11:49 PM - edited 04-12-2013 12:04 AM
04-11-2013 11:49 PM - edited 04-12-2013 12:04 AM
Hi Guru's,
I have a requirement to convert text paragraph as below.Could you please someone help on this,
My Input is
====
6XN1LK2B xxxxx07 /dev/rhdisk0 292968750
6XN1MBA1 xxxxx07 /dev/rhdisk1 292968750
6XN1MXKA xxxxx07 /dev/rhdisk2 292968750
6XN1MWEH xxxxx07 /dev/rhdisk3 292968750
2350BED0 xxxxx07 /dev/rhdisk5 62914560
404FB47D xxxxx07 /dev/rhdisk6 62914560
434FB47D xxxxx07 /dev/rhdisk7 62914560
454FFA70 xxxxx07 /dev/rhdisk8 62914560
464FFA70 xxxxx07 /dev/rhdisk9 62914560
8050AF2D xxxxx07 /dev/rhdisk10 31457280
8150AF2D xxxxx07 /dev/rhdisk11 31457280
8250AF2D xxxxx07 /dev/rhdisk12 31457280
8350D043 xxxxx07 /dev/rhdisk13 62914560
8450D043 xxxxx07 /dev/rhdisk14 62914560
====
6XN1LK2B xxxxx06 /dev/rhdisk0 292968750
6XN1MBA1 xxxxx06 /dev/rhdisk1 292968750
6XN1MXKA xxxxx06 /dev/rhdisk2 292968750
6XN1MWEH xxxxx06 /dev/rhdisk3 292968750
2350BED0 xxxxx06 /dev/rhdisk5 62914560
404FB47D xxxxx06 /dev/rhdisk6 62914560
434FB47D xxxxx06 /dev/rhdisk7 62914560
454FFA70 xxxxx06 /dev/rhdisk8 62914560
464FFA70 xxxxx06 /dev/rhdisk9 62914560
8050AF2D xxxxx06 /dev/rhdisk10 31457280
8150AF2D xxxxx06 /dev/rhdisk11 31457280
8250AF2D xxxxx06 /dev/rhdisk12 31457280
8350D043 xxxxx06 /dev/rhdisk13 62914560
8450D043 xxxxx06 /dev/rhdisk14 62914560
====
6XN1LK2B xxxxx05 /dev/rhdisk0 292968750
6XN1MBA1 xxxxx05 /dev/rhdisk1 292968750
6XN1MXKA xxxxx05 /dev/rhdisk2 292968750
6XN1MWEH xxxxx05 /dev/rhdisk3 292968750
2350BED0 xxxxx05 /dev/rhdisk5 62914560
404FB47D xxxxx05 /dev/rhdisk6 62914560
434FB47D xxxxx05 /dev/rhdisk7 62914560
454FFA70 xxxxx05 /dev/rhdisk8 62914560
464FFA70 xxxxx05 /dev/rhdisk9 62914560
8050AF2D xxxxx05 /dev/rhdisk10 31457280
8150AF2D xxxxx05 /dev/rhdisk11 31457280
8250AF2D xxxxx05 /dev/rhdisk12 31457280
8350D043 xxxxx05 /dev/rhdisk13 62914560
8450D043 xxxxx05 /dev/rhdisk14 62914560
====
Output should be link this.
6XN1LK2B xxxxx07 /dev/rhdisk0 292968750 6XN1LK2B xxxxx06 /dev/rhdisk0 292968750 6XN1LK2B xxxxx05 /dev/rhdisk0 292968750
6XN1MBA1 xxxxx07 /dev/rhdisk1 292968750 6XN1MBA1 xxxxx06 /dev/rhdisk1 292968750 6XN1MBA1 xxxxx05 /dev/rhdisk1 292968750
6XN1MXKA xxxxx07 /dev/rhdisk2 292968750 6XN1MXKA xxxxx06 /dev/rhdisk2 292968750 6XN1MXKA xxxxx05 /dev/rhdisk2 292968750
6XN1MWEH xxxxx07 /dev/rhdisk3 292968750 6XN1MWEH xxxxx06 /dev/rhdisk3 292968750 6XN1MWEH xxxxx05 /dev/rhdisk3 292968750
2350BED0 xxxxx07 /dev/rhdisk5 62914560 2350BED0 xxxxx06 /dev/rhdisk5 62914560 2350BED0 xxxxx05 /dev/rhdisk5 62914560
404FB47D xxxxx07 /dev/rhdisk6 62914560 404FB47D xxxxx06 /dev/rhdisk6 62914560 404FB47D xxxxx05 /dev/rhdisk6 62914560
434FB47D xxxxx07 /dev/rhdisk7 62914560 434FB47D xxxxx06 /dev/rhdisk7 62914560 434FB47D xxxxx05 /dev/rhdisk7 62914560
454FFA70 xxxxx07 /dev/rhdisk8 62914560 454FFA70 xxxxx06 /dev/rhdisk8 62914560 454FFA70 xxxxx05 /dev/rhdisk8 62914560
464FFA70 xxxxx07 /dev/rhdisk9 62914560 464FFA70 xxxxx06 /dev/rhdisk9 62914560 464FFA70 xxxxx05 /dev/rhdisk9 62914560
8050AF2D xxxxx07 /dev/rhdisk10 31457280 8050AF2D xxxxx06 /dev/rhdisk10 31457280 8050AF2D xxxxx05 /dev/rhdisk10 31457280
8150AF2D xxxxx07 /dev/rhdisk11 31457280 8150AF2D xxxxx06 /dev/rhdisk11 31457280 8150AF2D xxxxx05 /dev/rhdisk11 31457280
8250AF2D xxxxx07 /dev/rhdisk12 31457280 8250AF2D xxxxx06 /dev/rhdisk12 31457280 8250AF2D xxxxx05 /dev/rhdisk12 31457280
8350D043 xxxxx07 /dev/rhdisk13 62914560 8350D043 xxxxx06 /dev/rhdisk13 62914560 8350D043 xxxxx05 /dev/rhdisk13 62914560
8450D043 xxxxx07 /dev/rhdisk14 62914560 8450D043 xxxxx06 /dev/rhdisk14 62914560 8450D043 xxxxx05 /dev/rhdisk14 62914560
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2013 12:37 AM - edited 04-12-2013 09:23 PM
04-12-2013 12:37 AM - edited 04-12-2013 09:23 PM
Re: Row to column conversion
You have one file where you have multiple groups (separated by "===="?) and you want to combine them and put each group as a column group where the key is the first field?
Do you care if you sort the whole file and columns can come from any part of the file?
I.e instead of:
6XN1LK2B xxxxx07 /dev/rhdisk0 292968750 6XN1LK2B xxxxx06 /dev/rhdisk0 292968750 6XN1LK2B xxxxx05 /dev/rhdisk0 292968750
You get:
6XN1LK2B xxxxx05 /dev/rhdisk0 292968750 /dev/rhdisk0 292968750 6XN1LK2B xxxxx06 /dev/rhdisk0 292968750
Do you care that the first column is sorted? (Your example output isn't.)
I.e. Sort the whole file, if multiple rows with same key, create another column group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2013 12:57 AM - edited 04-12-2013 01:01 AM
04-12-2013 12:57 AM - edited 04-12-2013 01:01 AM
Re: Raw to column conversion
Hi Dennis,
Thanks for quick reply.
You have one file where you have multiple groups (separated by "===="?) and you want to combine them and put each group as a column group where the key is the first field?
yes.Correct.
Do you care if you sort the whole file and columns can come from any part of the file?
I.e instead of:
6XN1LK2B xxxxx07 /dev/rhdisk0 292968750 6XN1LK2B xxxxx06 /dev/rhdisk0 292968750 6XN1LK2B xxxxx05 /dev/rhdisk0 292968750
You get:
6XN1LK2B xxxxx05 /dev/rhdisk0 292968750 /dev/rhdisk0 292968750 6XN1LK2B xxxxx06 /dev/rhdisk0 292968750
I want text as it is.
basically first column is identical(6XN1LK2B,6XN1MBA1-luns) for all servers(XXXXX05,06,07) .My requirement is to check each lun avialability in all the servers.
Do you care that the first column is sorted? (Your example output isn't.)
I.e. Sort the whole file, if multiple rows with same key, create another column group.
Many thanks once agian.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2013 09:45 PM - edited 04-15-2013 03:44 AM
04-12-2013 09:45 PM - edited 04-15-2013 03:44 AM
Solution>I want text as it is.
This is too hard, I'm just sorting and merging. I did see duplicates for 8350D043 with multiple disks, so I merge if the first and third columns match:
# Sorts the data by column 1 and 3 then merges matches to same line
sed -e '/====/d' input-file | sort -k1,1 -k3,3 | awk '
BEGIN { key1 = ""; key2 = ""; save = "" }
key1 == $1 && key2 == $3 {
save = save " " $0 # combine
next
}
# no match
{
if (save != "")
print save
key1 = $1
key2 = $3
save = $0
}
END {
if (save != "")
print save
} '
Output looks like:
2350BED0 xxxxx05 /dev/rhdisk5 62914560 2350BED0 xxxxx06 /dev/rhdisk5 62914560 2350BED0 xxxxx07 /dev/rhdisk5 62914560
...
8350D043 xxxxx05 /dev/rhdisk13 62914560 8350D043 xxxxx06 /dev/rhdisk13 62914560 8350D043 xxxxx07 /dev/rhdisk13 62914560
8450D043 xxxxx05 /dev/rhdisk14 62914560 8450D043 xxxxx06 /dev/rhdisk14 62914560 8450D043 xxxxx07 /dev/rhdisk14 62914560
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2013 03:29 AM
04-15-2013 03:29 AM
Re: Row to column conversion
Hi Dennis,
Thanks much.
I tried above code.
Its doesnt change anything in the input file.
# cat check
sed -e '/====/d' | sort -k1,1 -k3,3 | awk '
BEGIN { key1 = ""; key2 = ""; save = "" }
key1 == $1 && key2 == $3 {
save = save " " $0 # combine
next
}
# no match
{
if (save != "")
print save
key1 = $1
key2 = $3
save = $0
}
END {
if (save != "")
print save
} ' input_file
# sh check
6XN1LK2B gepvio08 /dev/rhdisk0 292968750
6XN1MBA1 gepvio08 /dev/rhdisk1 292968750
6XN1MXKA gepvio08 /dev/rhdisk2 292968750
6XN1MWEH gepvio08 /dev/rhdisk3 292968750
2350BED0 gepvio08 /dev/rhdisk5 62914560
404FB47D gepvio08 /dev/rhdisk6 62914560
434FB47D gepvio08 /dev/rhdisk7 62914560
454FFA70 gepvio08 /dev/rhdisk8 62914560
464FFA70 gepvio08 /dev/rhdisk9 62914560
8050AF2D gepvio08 /dev/rhdisk10 31457280
8150AF2D gepvio08 /dev/rhdisk11 31457280
8250AF2D gepvio08 /dev/rhdisk12 31457280
8350D043 gepvio08 /dev/rhdisk13 62914560
8450D043 gepvio08 /dev/rhdisk14 62914560
===
6XN1LK2B gepvio07 /dev/rhdisk0 292968750
6XN1MBA1 gepvio07 /dev/rhdisk1 292968750
6XN1MXKA gepvio07 /dev/rhdisk2 292968750
6XN1MWEH gepvio07 /dev/rhdisk3 292968750
2350BED0 gepvio07 /dev/rhdisk5 62914560
404FB47D gepvio07 /dev/rhdisk6 62914560
434FB47D gepvio07 /dev/rhdisk7 62914560
454FFA70 gepvio07 /dev/rhdisk8 62914560
464FFA70 gepvio07 /dev/rhdisk9 62914560
8050AF2D gepvio07 /dev/rhdisk10 31457280
8150AF2D gepvio07 /dev/rhdisk11 31457280
8250AF2D gepvio07 /dev/rhdisk12 31457280
8350D043 gepvio07 /dev/rhdisk13 62914560
8450D043 gepvio07 /dev/rhdisk14 62914560
===
6XN1LK2B gepvio06 /dev/rhdisk0 292968750
6XN1MBA1 gepvio06 /dev/rhdisk1 292968750
6XN1MXKA gepvio06 /dev/rhdisk2 292968750
6XN1MWEH gepvio06 /dev/rhdisk3 292968750
2350BED0 gepvio06 /dev/rhdisk5 62914560
404FB47D gepvio06 /dev/rhdisk6 62914560
434FB47D gepvio06 /dev/rhdisk7 62914560
454FFA70 gepvio06 /dev/rhdisk8 62914560
464FFA70 gepvio06 /dev/rhdisk9 62914560
8050AF2D gepvio06 /dev/rhdisk10 31457280
8150AF2D gepvio06 /dev/rhdisk11 31457280
8250AF2D gepvio06 /dev/rhdisk12 31457280
8350D043 gepvio06 /dev/rhdisk13 62914560
8450D043 gepvio06 /dev/rhdisk14 62914560
===
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2013 03:45 AM - edited 04-15-2013 09:50 AM
04-15-2013 03:45 AM - edited 04-15-2013 09:50 AM
Re: Row to column conversion
>It doesn't change anything in the input file.
Oops, I put the input-file on the wrong stage of the pipeline. See corrected script.
(I initially tested with a here-doc.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2013 09:34 AM
04-15-2013 09:34 AM
Re: Row to column conversion
Hi Dennis,
Its works perfectly fine now.
Many thanks.