0

I am unsure if I am misunderstanding something or just not searching correctly. However, I have an issue that I am testing with a simple echo command and piping to sed to replace part of the string that matches $SYNC and replaces with /home/pi/sync

here is what I am using for testing:

echo '$SYNC/somedirectory' | sed 's|"$SYNC"|"/home/pi/sync"|'

it keeps giving back

$SYNC/somedirectory

It was my understand that the above sed command would replace $SYNC with /home/pi/sync

I will be using it in part of a larger line that follows:

grep -w "file_path =" /home/pi/lightshowpi/config/state.cfg | sed 's/.*= //'| (this is where I need to replace the $SYNC with /home/pi/sync) | xargs mp3info -p "%a"

essentially, I am getting the line with the file path and grabbing everything after the '= ' which returns the $SYNC/file.mp3 which then I can pipe into mp3info to get the mp3 information.

I have tried without a second sed command but the Environment variable doesn't get expanded and it returns an error of no such directory such as:

$SYNC/mp3file.mp3 does not exist

but when I replace the $SYNC manually with /home/pi/sync/mp3file.mp3 it works fine.

I am open to any other way of doing so without using sed, I just figured sed would be the simplest way to do so.

1

I have figured out the answer, it was a simple mistake due to my inexperience with shell

grep -w "file_path =" /home/pi/lightshowpi/config/state.cfg | sed 's/.*= //'| sed 's|'\$SYNC'|'/home/pi/sync'|' | xargs mp3info -p "%a"

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.