- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- generalizing fields for 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
Discussions
Discussions
Forums
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
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
тАО08-25-2004 01:09 AM
тАО08-25-2004 01:09 AM
I have a file that has about 16 columns delimited by comma(","). I need to append only the first two columns by hyphen("-"). For that I am doing some thing like below
awk -F, 'OFS=","{print $1"-"$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16}' my_file
Is there any way of generalising the columns from 3 to 16??
I am expecting some thing like
awk -F, 'OFS=","{print $1"-"$2,$3-$16}' my_file
Is this possible?
Please kindly help.
Thanks and Regards,
-Parmy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2004 01:19 AM
тАО08-25-2004 01:19 AM
Re: generalizing fields for Awk
awk '{ printf $1"-" ; for(i=2; i<=NF; i++) { printf ","$i } ; printf "\n" }' my_file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2004 01:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2004 01:40 AM
тАО08-25-2004 01:40 AM
Re: generalizing fields for Awk
perl -p -e 's/,/-/' my_file
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2004 01:53 AM
тАО08-25-2004 01:53 AM
Re: generalizing fields for Awk
you just can use sed command to substitute the 1st comma :
cat
Regards
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2004 02:17 AM
тАО08-25-2004 02:17 AM
Re: generalizing fields for Awk
echo "a,b,c,d,e,f,g,h,i,j,k,l,i,j,k,l" | awk -F , '{ printf $1"-"
> for ( i=2; i
> } END { printf $NF }'
output:
a-b,c,d,e,f,g,h,i,j,k,l,i,j,k,l
Or just easy as,
echo "a,b,c,d,e,f,g,h,i,j,k,l,i,j,k,l" | sed -e 's/,/-/1'
It will change first occurence of , and change it to -
Regards
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2004 04:40 AM
тАО08-25-2004 04:40 AM
Re: generalizing fields for Awk
but if your data is already comma delimited,
all you need to do is change the first comma
awk '{sub(",","-");print $0;}'
or using sed
sed -e 's/,/-/'
and you already have a perl example
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2004 10:38 PM
тАО08-25-2004 10:38 PM
Re: generalizing fields for Awk
Thanks a lot for your time helping me to know about generalising. I am impressed by all your replies and thanks again.
Regards,
Parmy