LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-24-2008, 06:54 AM   #1
i.you
Member
 
Registered: Oct 2006
Posts: 46

Rep: Reputation: 15
awk help


Hi

I'd like to split a string and I used awk :

Quote:
#!/bin/sh

string="sun,mon,tue,wed"
awk 'BEGIN { split{string, array, ",") }'
for i in 0 1 2 3
do
echo ${array[i]}
done
Is it wrong?
It doesn't work;...

Any help?
 
Old 03-24-2008, 06:57 AM   #2
livetoday
Member
 
Registered: Jun 2006
Location: India
Distribution: RHEL,Suse,Fedora
Posts: 106

Rep: Reputation: 15
Is this what you want ??

echo "sun,mon,tue" | sed 's/,/\n/g'

suniL

Quote:
Originally Posted by i.you View Post
Hi

I'd like to split a string and I used awk :



Is it wrong?
It doesn't work;...

Any help?
 
Old 03-24-2008, 07:28 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
echo $string | awk 'BEGIN {FS=","; OFS="\n"}{$1=$1;print $0}'

Inside the awk command, string is an awk variable and not a bash variable.
You could have a bash variable evaluated in the command line. But that isn't the same thing as manipulating a bash variable:
echo | awk 'BEGIN {string='\"$string\"'}{print "the input: " string}'
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
awk question on handling *.CSV "text fields" in awk jschiwal Programming 8 05-27-2010 07:23 AM
Some comments on awk and awk scripts makyo Programming 4 03-02-2008 06:39 PM
awk help uttam_h Linux - Software 4 12-17-2007 10:40 PM
help with awk sang_froid Programming 1 07-05-2007 02:35 PM
using awk meniscus Linux - Newbie 6 10-05-2006 01:39 PM


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

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration