1

I have a file in which I have to convert the string "lock allpages" into STRING " LOCATION 'hdfs://LOCATION/DIRECTORY/TBL;' " . I tried sed but it's throwing some error. can someone suggest the changes that I need to do. I tried below but it's not working. and also can someone suggest how to use sed for replacing multiple strings at once

sed -i 's/lock allpages/LOCATION 'hdfs://LOCATION/DIRECTORY/TBL';'
1
  • "it's throwing some error" -- what error exactly? "it's not working" -- what is it doing and how does that differ from what you expect? See How do I ask a good question? Commented Jun 23, 2021 at 18:24

1 Answer 1

2

You need to escape your single quotes and forward slashes in your sed statement. .. That and you're not COMPLETING the sed statement .. You need to close your second argument with a slash -> / (Or whatever delimiter you choose)

sed -i 's/lock allpages/LOCATION \'hdfs:\/\/LOCATION\/DIRECTORY\/TBL;\'/g' 

OR if you put the statement in double quotes . There's no need to escape the single quotes

sed -i "s/lock allpages/LOCATION 'hdfs:\/\/LOCATION\/DIRECTORY\/TBL;'/g" 

FURTHER -- If you used a different delimiter .. Like a pipe | -- There would be no need for escaping at all...

sed -i "s|lock allpages|LOCATION 'hdfs://LOCATION/DIRECTORY/TBL;'|g" 
Sign up to request clarification or add additional context in comments.

1 Comment

You cannot escape a single quote inside a single quoted string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.