- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk - single character field separator
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
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
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-19-2005 03:14 AM
тАО04-19-2005 03:14 AM
echo hello | awk 'BEGIN { FS = "" } ; {print $1}
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 03:47 AM
тАО04-19-2005 03:47 AM
Re: awk - single character field separator
From the gnu website:
Traditionally, the behavior of FS equal to "" was not defined. In this case, most versions of Unix awk simply treat the entire record as only having one field. (d.c.)
-P
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 03:51 AM
тАО04-19-2005 03:51 AM
Re: awk - single character field separator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 03:54 AM
тАО04-19-2005 03:54 AM
Re: awk - single character field separator
/root# echo hello | awk 'BEGIN { FS="" } ; {print $1}'
hello
download and install gawk + libiconv from
http://hpux.connect.org.uk/hppd/hpux/Gnu/gawk-3.1.4/
Regards,
Robert-Jan
- Tags:
- gawk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 03:55 AM
тАО04-19-2005 03:55 AM
Re: awk - single character field separator
In Linux you could also do
echo hello | awk -F "" '{print $1}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 03:57 AM
тАО04-19-2005 03:57 AM
Re: awk - single character field separator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 03:59 AM
тАО04-19-2005 03:59 AM
Re: awk - single character field separator
echo hello | awk 'BEGIN {FIELDWIDTHS=1} { print $1 }'
But sadly, this doesn't help with your problem, as the output on HP is 'hello'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 04:06 AM
тАО04-19-2005 04:06 AM
Re: awk - single character field separator
Could you use the substr() function within perl or shell?
What about sed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 04:18 AM
тАО04-19-2005 04:18 AM
Re: awk - single character field separator
I understood your request. I included the clip from the gnu site to try to explain that this is a feature of GNU only, and that UNIX awk doesn't let you do it. Sorry if that wasn't clear.
-paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 04:20 AM
тАО04-19-2005 04:20 AM
Re: awk - single character field separator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 05:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 05:42 AM
тАО04-19-2005 05:42 AM
Re: awk - single character field separator
echo hello | sed "s/\(.\)/& /g" | awk '{printf("f1(%s) f2(%s) f3(%s) f4(%s) f5(%s)\n",$1,$2,$3,$4,$5);}
f1(h) f2(e) f3(l) f4(l) f5(o)
or
echo hello | sed "s/\(.\)/& /g" | awk '{print $5,$4,$3,$2,$1;}'
o l l e h
live free or die
harry d brown jr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 05:53 AM
тАО04-19-2005 05:53 AM
Re: awk - single character field separator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 06:51 PM
тАО04-19-2005 06:51 PM
Re: awk - single character field separator
We can simply use:
echo hello | sed "s/./& /g" | awk '{print $5,$4,$3,$2,$1;}'
I know we can use any general os command in awk block, but somehow i am unable to figure out how.
Can someone help me start it out.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2005 07:11 PM
тАО04-19-2005 07:11 PM
Re: awk - single character field separator
h e l l o
lt09:/home/merijn 111 > echo hello | perl -lne'$,=" ";print reverse split//'
o l l e h
lt09:/home/merijn 112 >
Enjoy, Have FUN! H.Merijn
- Tags:
- Perl