0

I have a script to download video from youtube but i want to add ss just after the www. to it will be converted into www.ssyoutube.com

 #!/bin/bash
 dialog --inputbox "Enter Video's Link..." 10 30 2>/tmp/video.txt
 video=`cat /tmp/video.txt`       
 edit=ss 
 echo $video
 sleep 5;
 wget $video

2 Answers 2

1

Parameter Expansion can do this for you in bash.

video="www.youtube.com"
edit="ss"
video="${video/www./www.$edit}"
echo "$video"                   # www.ssyoutube.com

man bash → search for "Pattern substitution."

(Sure, sed works too, but for a simple string substitution it's much more efficient to use bash's built-in feature than to fork a new process.)

Sign up to request clarification or add additional context in comments.

Comments

0

You could use sed. Use a escaped dot in your regex to match a literal dot.

sed 's/www\./www.ss/g' file

ie,

sed -i 's/www\./www.ss/g' /tmp/video.txt

Comments

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.