LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Other *NIX
User Name
Password
Other *NIX This forum is for the discussion of any UNIX platform that does not have its own forum. Examples would include HP-UX, IRIX, Darwin, Tru64 and OS X.

Notices

Reply
 
LinkBack Search this Thread
Old 04-02-2013, 01:59 PM   #1
brgr88
Member
 
Registered: Apr 2006
Distribution: Slackware 14
Posts: 46

Rep: Reputation: 15
Non-GNU awk Splitting Single Characters In A String?


I'm learning awk, and trying to split a string into single characters, either to print them out one line at a time, or just store them in an array.

Rather than looping with substr(), I'm trying to use a null string as FS, and came across this on the net:
echo "blah" | awk 'BEGIN FS=""} {for (i=1; i<=NF; i++) print $(i) }'

It works as expected on my GNU Linux box, but on an HP-UX box at work, it only prints the input string as-is:
blah

I'd thought that setting FS to a null string would accomplish this, but it doesn't appear to work on the "other" UNIXes.

Is this correctly the case? Do older, non-GNU, versions of awk not allow FS to be a null string to split on characters?

My HP-UX machine is (uname -a):
HP-UX nodename B.11.11 U 9000/800 ....
 
Old 04-02-2013, 04:11 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,157

Rep: Reputation: 493Reputation: 493Reputation: 493Reputation: 493Reputation: 493
Quote:
Originally Posted by brgr88 View Post
Do older, non-GNU, versions of awk not allow FS to be a null string to split on characters?
Excerpt from the gawk manpage:
GNU EXTENSIONS
The ability to split out individual characters using the null string as the value of FS, and as the third argument to split().
So yes, it's a GNUism.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Splitting string into variables tsdjim Programming 8 02-17-2013 03:58 PM
[SOLVED] Sed/awk/cut to pull a repeating string out of a longer string StupidNewbie Programming 3 03-21-2012 01:47 PM
[SOLVED] [bash - sed - awk] Match line with x characters and add string TigerClaw Linux - Newbie 4 02-28-2012 12:22 AM
splitting string bregtux Programming 12 08-23-2011 01:43 AM
splitting numbers and characters from an array of characters. trscookie Programming 6 11-14-2008 09:34 AM


All times are GMT -5. The time now is 11:10 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration