Search code examples
sedcut

Remove ".200.300." from string


What's the best way to take a string such as:

100.200.300.400

And remove the ".200.300." portion of the string leaving "100400".?

UPDATE: Adding some additional context. :) We use Jamf Pro to patch apps on macOS. We use Extension Attributes (EAs) to determine if a computer is in desired state (has the version we are deploying or later). Currently we use multiple EAs, which is not very efficient. Using Adobe Flash Player as an example, the version is always NN.0.0.NNN format. If we remove ".0.0." from the version string, we can have an integer to perform an "-ge" analysis. The end result is we would know if computer is in desired state (app is at desired version or later), or not in desired state (needs update), or not installed (nothing to do). Here is an example of a script I used, using the input from you guys:

#!/bin/sh

plistFile="/Library/Internet Plug-Ins/Flash Player.plugin/Contents/version.plist"
versionString=$( defaults read "$plistFile" CFBundleShortVersionString )
currentState=$( echo "${versionString}" | sed 's/\..*\.//' )
desiredState="32114"

if [ -e "$plistFile" ]
then
    if [[ "${currentInteger}" -ge "${desiredInteger}" ]]
    then
        echo "<result>DesiredState</result>"
    else
        echo "<result>NeedsUpdate</result>"
    fi
else
    echo "<result>NotInstalled</result>"
fi

exit 0

Solution

  • Could you please try following.

    echo "100.200.300.400" | sed 's/\..*\.//'