sub and gsub function?
awk, r, substring
Solution
That won't work if the string contains more than one match... try this:
echo "/x/y/z/x" | awk '{ gsub("/", "_") ; system( "echo " $0) }'
or better (if the `echo` isn't a placeholder for something else):
echo "/x/y/z/x" | awk '{ gsub("/", "_") ; print $0 }'
In your case you want to make a copy of the value before changing it:
echo "/x/y/z/x" | awk '{ c=$0; gsub("/", "_", c) ; system( "echo " $0 " " c )}'
Problem
I have this command: ``` $ find $PWD -name "*.jpg" | awk '{system( "echo " $(sub(/\//, "_")) ) }' _home/mol/Pulpit/test/1.jpg ``` Now the same thing, but using gsub: ``` $ find $PWD -name "*.jpg" | awk '{system( "echo " $(gsub(/\//, "_")) ) }' mol@mol:~ ``` I want to get the result: ``` _home_mol_Pulpit_test_1.jpg ``` Thank you for your help. EDIT: I put 'echo' to test the command: ``` $ find $PWD -name "*.jpg" | awk '{gsub("/", "_")} {system( "echo " mv $0 " " $0) }' _home_mol_Pulpit_test_1.jpg _home_pic_Pulpit_test_1.jpg mol@mol:~ ``` I want to get the result: ``` $ find $PWD -name "*.jpg" | awk '{gsub("/", "_")} {system( "echo " mv $0 " " $0) }' /home/pic/Pulpit/test/1.jpg _home_pic_Pulpit_test_1.jpg ```