I have a file with lines like these:
0105:ffff0000:001b:01f4:25:434
0299:ffff0000:0009:01f4:2:319
02d2:ffff0000:000e:01f4:2:507
The above values are split up using ":" characters.
I would like capture each value, no matter what length.
Take for example the first line 0105:ffff0000:001b:01f4:25:434.
First value: 0105 (should be captured from the start of the line until the first ":")
Second value: ffff0000 (everything between the first ":" and the second ":")
Third value: 001b (everything betweed the second ":" and the third ":")
and so on..
There is always 6 values split up between 5 ":"-characters.
I tried the following for the first value:
while read line
do
first=`echo $line | sed "s/^\(....\).*/\1/"`
echo $first
#second=`echo $line | sed ??`
#third=`echo $line | sed ??`
#fourth=`echo $line | sed ??`
#fifth=`echo $line | sed ??`
#sixth=`echo $line | sed ??`
done<file.txt
This will print the first four characters from the line for the $first var.
The first value is always four characters long, but the rest of the values can differ in length.
That's why I need to do the above approach by only looking between the ":"-characters.
Is it possible by only using sed?
I'm afraid the environment doesn't ship with "awk".
So there is no way to do the same thing with only sed?
If not then I'll have to ask the software-maintainer to recompile a new build for our platform including awk.
$ while read line
> do
> echo "$line" | sed 's/:/ /g' | while read a b c d e f
> do
> echo $a
> echo $b
> echo $c
> echo $d
> echo $e
> echo $f
> done
> done < input_file