Hi,
I've a string "200910/22-101010" ( this is date and time string YYYYMMDD/HHMMSS format) , how can i remove "/" and assign it to a new variable a value of 20091022 only
thanks
Hi,
I've a string "200910/22-101010" ( this is date and time string YYYYMMDD/HHMMSS format) , how can i remove "/" and assign it to a new variable a value of 20091022 only
thanks
echo 200910/22-101010 | sed "s/\///"
string=200910/22-101010
temp=${string%-*}
IFS=/ read a b <<EOF
$temp
EOF
newvar=$a$b
string="200910/22-101010"
echo ${string%-*}|tr -d "/"
20091022
For completeness: -
new_variable=$(echo ${string%-*}|tr -d "/")
echo $new_variable
20091022
foo="200910/22-101010"
foo=${foo%%-*}
foo=${foo//\//}
echo $foo
ds="200910/22-101010"
posix:
ds=${ds%-*}
newvar=${ds%/*}${ds#*/}
ksh/bash:
ds=${ds%-*}
newvar=${ds/\/}
tr:
newvar=$(echo ${ds%-*}|tr -d '/')
sed:
newvar=$(echo $ds|sed 's|/||;s|-.*||')
-or-
newvar=$(echo $ds|sed 's|/\(..\).*|\1|')
awk:
newvar=$(echo $ds|awk -F '[/-]' '{print $1$2}')
$ foo=${foo//\//}
echo $foo$ $ Syntax error: Bad substitution