so i want to avoid external calls in my script, so im trying to do the following:
AllMyLogs="hello---nallo---wello---bollo
tello---zello---jello---kello"
OLDIFS="$IFS\\\n"
IFS="---"
set -- ${AllMyLogs}
IFS="$OLDIFS"
I want it to work in a way that, when i type this:
echo $2
I get:
nallo
zello
basically, id like to pick the field/column that i want to grab, without having to use awk. Any ideas??
I want this to work on any unix os, so the solution would have to be portable.
That isn't the way IFS
works. Every character in $IFS
is treated as a field separator; it is not an ERE as in FS
in awk
.
And, that isn't the way set --
works. There is only one set of positional parameters, not one set for each <newline> character encountered in the arguments passed to set
.
But (assuming that the text between your ---
field separators does not include any -
characters), you could try something like:
printf '%s\n' "hello---nallo---wello---bollo
tello---zello---jello---kello" |
while IFS='-' read -r junk junk junk data junk
do printf '%s\n' "$data"
done
1 Like