awk to split string

Hello Friends,

Im trying to split a string. When i use first method of awk like below i have an error:

method1 (I specified the FS as ":" so is this wrong?)

servert1{root}>awk -f split.txt 
awk: syntax error near line 2
awk: bailing out near line 2

split.txt:

myString="apple:orange:banana";
split(myString,fruits,":");
print fruits[1];
print fruits[2];
print fruits[3];

method2 (when i run command without calling text file it does not response just waits :confused: )

awk '{split("apple:orange:banana",fruits,":")} END{print fruits[1],fruits[2],fruits[3]}'

pls help me to find out what is wrong with the commands

awk 'BEGIN{split(ARGV[1],fruits,":");print fruits[1],fruits[2],fruits[3]}' "apple:orange:banana"

Danmero i tested but it gave error

awk: can't open apple:orange:banana

but you gave me the idea adding BEGIN and a ";" after closing the phranthesis and it worked

awk 'BEGIN{split("apple:orange:banana",fruits,":"); print fruits[1],fruits[2],fruits[3]}'
apple orange banana

thnx

hi ppl,
I have a basic doubt as to how shell treats strings.
e.g:given a line of data like this "5","6","45","77","89"
extracting the value from each field to a variable will conatin a string("5") or just the number?
If it conatins "5", how do we perform mathematical operations with that variable?

Beetel you should create a new thread for your question as it is not related to this thread. I'd recommend you to read forum rules and stroll around here to find out about the forum..

oops sorry! beginner...