- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: grouping data using awk
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
Forums
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
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
02-01-2008 12:43 AM
02-01-2008 12:43 AM
I am trying to group data present in one variable.
i am using below code:
myoutput=`echo $a | awk '{out=$1;for (k=2;k<=NF;k++){out=sprintf("%s,%s",out,$k);}print out}'`
value of var a is:
1
2
1
2
my output is:
echo $myoutput
1,2,1,2
**************************************
Now here i want to put one condition in awk that:
if $k = 1 then
$out="INTERIM"
if $k = 2 then
$out="PERMANENT"
hence my out put should be like:
echo $myoutput
INTERIM,PERMANENT,INTERIM,PERMANENT
Could some pelase suggest how to make this changes?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2008 03:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2008 03:43 AM
02-01-2008 03:43 AM
Re: grouping data using awk
Many thanks, It seems that it is working.
One clarification:
in your code what is the use of :
return ins # error case? line
Shall i remove this? Is it have any impact?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2008 03:49 AM
02-01-2008 03:49 AM
Re: grouping data using awk
return ins # error case? line
>Shall i remove this? Is it have any impact?
If you want to change "k" only for 1 or 2, you need that assignment to leave it unchanged. So you should change the comment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2008 04:28 AM
02-01-2008 04:28 AM
Re: grouping data using awk
I am going to use for only 1 or 2. There will be no values other than 1 or 2.
So shall i leave it as it is?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2008 04:38 AM
02-01-2008 04:38 AM
Re: grouping data using awk
>So shall i leave it as it is?
You might as well, even the comment. That suggests how you can extend the function. Otherwise you could optimize it as:
if (ins == 1)
return "INTERIM"
else
return "PERMANENT"