1

The final.txt looks like:

build/create_changes.sh
build/create_changes.sh-meta.xml
src/aura/camping/camping.design
src/aura/camping/camping.design-meta.xml

And the code looks like this:

if [ -e final.txt ]
then
    ARRAY=()
    while read CFILE
    do
        echo Analyzing file `basename $CFILE`
        case "$CFILE"
            in
            *.design) TYPENAME="AuraDefinitionBundle";;
            *) TYPENAME="UNKNOWN";;
        esac

        if [ "$TYPENAME" == "AuraDefinitionBundle" ]
        then
            if [ $(contains "${ARRAY[@]}" $(basename -- "$(dirname -- "$CFILE")")) != "y" ]
            then
                echo baseFile from new method cFile $CFILE
                CFILENAME="$CFILE"

                replace="src/aura/"$(basename -- "$(dirname -- "$CFILE")")
                echo checkChanges "${CFILENAME/$CFILENAME/"$replace"}"
                CFILE="${CFILENAME/$CFILENAME/"$replace"}"
                echo baseFile from after change method cFile $CFILE
            else
                continue
            fi
        fi
    done < final.txt
else
    echo Change file not found!

I can see in echo window as :

 [exec] baseFile from new method cFile src/aura/camping/camping.design
 [exec] checkChanges src/aura/camping
 [exec] baseFile from after change method cFile src/aura/camping

but the file does not change, I even added sed command but the output does not change:

if [ $(contains "${ARRAY[@]}" $(basename -- "$(dirname -- "$CFILE")")) != "y" ]
then
    CFILENAME="$CFILE"
    ARRAY+=($(basename -- "$(dirname -- "$CFILE")"))
    replace="src/aura/"$(basename -- "$(dirname -- "$CFILE")")
    #CFILE="${CFILENAME/$CFILENAME/"$replace"}"
    sed -i 's/$CFILENAME/$replace/' final.txt
else
    continue
fi

Expected Input

build/create_changes.sh
build/create_changes.sh-meta.xml
src/aura/camping/camping.design
src/aura/camping/camping.design-meta.xml

Expected output

build/create_changes.sh
build/create_changes.sh-meta.xml
src/aura/camping
src/aura/camping/camping.design-meta.xml
  • The sed command doesn't work as the single quotes prevent the variables' expansion. Did you consider doing the entire operation in an e.g. awk script? – RudiC Sep 21 '18 at 8:36
0

I'm not sure I can follow your logics, but this

awk '/\.design$/ {sub("/[^/]*$", "")} 1 ' file
build/create_changes.sh
build/create_changes.sh-meta.xml
src/aura/camping
src/aura/camping/camping.design-meta.xml

would yield the desired output...

0

If you just want to delete the basename of all pathnames ending in .design:

sed 's#/[^/]*\.design$##' final.txt

To do an in-place edit, use sed -i with the above expression (there are slight variations of how the -i flag works, but this would work with GNU sed for example).

The regular expression /[^/]*\.design$ matches a / followed by any number of non-/ characters and the literal string .design at the end of a line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.