V
V
vldmr51502015-03-31 11:52:25
linux
vldmr5150, 2015-03-31 11:52:25

How to replace multiple occurrences in a string with sed?

Tell me, you need to convert the permissions displayed by the ls -l command from the rwx type to the read-write-execute type, without replacing r, w, x in the rest of the output.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Perminov, 2015-03-31
@vldmr5150

Maybe so?
a=$(ls -l | tail -n +2)
while read line
do
b=$(echo "$line" | awk '{print $1}' | sed -e 's/r/read/g' | sed -e 's/x/execute/g' | sed -e 's/w/write/g' )
c=$(echo "$line" | awk '{for (i=2; i<=NF; i++ ) print $i}')
echo $b $c >> ls.txt
done <<< "$a"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question