Kiran
Kiran

Reputation: 1053

sed token from : delimited string

I tried searching for an answer but lost in questions. Basically I have a shell script as follows:

#!/bin/ksh

if [ $# -eq 1 ]; then
    exit -1
fi 

processInfo $1

At this point, processInfo returns a string of format: param1:param2:param3:param4:param5

I want to capture param4 into a variable. ex: param4= processInfo $1 | sed regex

It seems to be simple with sed and regex but I just lost track of it. Pls help

Upvotes: 2

Views: 793

Answers (4)

glenn jackman
glenn jackman

Reputation: 247012

If you don't need to keep your script's positional parameters:

IFS=:
set -- $( processInfo "$1" )
param4="$4"

Upvotes: 0

Dennis Williamson
Dennis Williamson

Reputation: 360325

saveIFS=$IFS
IFS=:
array=($(processInfo $1))
IFS=$saveIFS
echo ${array[3]}

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799082

param4=$( processInfo "$1" | cut -d':' -f 4 )

Upvotes: 2

SiegeX
SiegeX

Reputation: 140417

param4=$(processInfo $1 | awk -F: '{print $4}')

Upvotes: 2

Related Questions