2

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

SiegeX
  • 135,741
  • 24
  • 144
  • 154
Kiran
  • 993
  • 2
  • 9
  • 14

4 Answers4

2
param4=$(processInfo $1 | awk -F: '{print $4}')
SiegeX
  • 135,741
  • 24
  • 144
  • 154
2
param4=$( processInfo "$1" | cut -d':' -f 4 )
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0
saveIFS=$IFS
IFS=:
array=($(processInfo $1))
IFS=$saveIFS
echo ${array[3]}
Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
0

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

IFS=:
set -- $( processInfo "$1" )
param4="$4"
glenn jackman
  • 238,783
  • 38
  • 220
  • 352