简体   繁体   中英

Bash script using find and grep

I am using bash script to match certain words but it's not working, it should give me color output using grep command.

warrior(){
    echo ""
    for i in ${sources[@]}
    do
    echo ""
    echo ""
        a=$(grep -n "\$_${i}" $f | grep -o "\$.*=" | sed "s/[ ]\?=//g" | sort -u)

        for j in ${sinks[@]}
        do
            grep --color -n "${j}.*\$_${i}" $f

            for k in $a
            do
                grep --color -n "${j}.*$k" $f
            done
        done
    done
}

if [ $f != "-r" ]
then
    warrior
else
    for i in $(find $2 -type f -name "*.*")
    do
        echo "File: $i"
        f=$i
        warrior
    done
fi

Expected output:

14:     document.getElementById('p1').innerHTML = 'Hello, ' + username + '!';
36: document.getElementById('p1').innerHTML = 'Current market index is ' + market.index + '.';

Error output:

./myprog.sh test
- empty results

All code is ok, error was grep -o and sed commands were extra also \$_ was being interpreted as EOL by grep, deleting it, fixed the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM