bash - Removing 2 last characters from a string -


i'm trying make list of directories 2 sources. other directory has entries can have -1 or -2 after them , want rid of them.

ls output example:

something.something.anything-1 stuff.stuff.stuff.morestuff-2 st.uf.f 

the code how have now:

echo -e "\tdata\t\t | \t\tsystem" system in `ls /system/app`;     data in `ls /data/app | sed 's/-1*$//' | sed 's/-2*$//'`;         echo -n "$data | "      done     echo "$system" done 

it works fine, i'm currious if there's better way of doing it, have use sed twice. , noticed there isn't many posts here remove characters strings using commands, place share ideas.

update:

the updated code:

echo -e "\tdata\t\t | \t\tsystem" system in `ls /system/app`;     data in `ls /data/app | sed 's/-[[:digit:]]*$//'`;         echo -n "$data | "      done     echo "$system" done 

wich works perfectly!

if want remove last 2 chars always:

echo "abcdefg" | sed 's/..$//g' > abcde 

or can use tighter regex digits

echo "abcdefg-2" | sed 's/-[[:digit:]]$//g' > abcdefg 

or two:

echo "abcdefg-2" | sed 's/-[12]$//g' > abcdefg 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -