I'll do my best to write correctly ( I'm from Spain ).
I have to create a sh to read from a flat file. Each field is delimited by ":", so each line could be like this:
field1:field2:field3 and so on.
I will create a file which can read a flat file containing 1..n fields.
I've done all the process, reading all the lines. Each line I read, I'm invoking to extract the substring, having the pattern ":".
echo $a | awk '{FS=":"}{print $1}{print $2}'
Where $a is the current line in the file. Since I don't know how many fields per line that the file can have, I need some way to know how many delimiters have the line.
print $1 prints all the text up to the delimiter.
print $2 same, until the second delimiter and so on...
There's some parameter that tells me how many delimiters are? ( Just like $@ or $* tells the number or parameters to a function, in example )
#!/bin/ksh
file=inputFile
while IFS=':' read a
do
set -- $a
printf "this line has %d columns: %s\n" "$#" "$a"
cnt=1
print "these are the fields"
while [ $cnt -le $# ]
do
eval print \$$cnt
cnt=$(( $cnt + 1 ))
done
done < ${file}