0

I am attempting to add a parameter based on an additional list 'list2.txt' that I have created and I am not quite sure how to implement it.

My running code

while read i
do
sed "s/Pie/$i/g" old_script.sh > new_script.$i.sh
sbatch new_script.$i.sh
done<list.txt

But I want to add the following condition with based on a new list... and I am not quite sure how to implement it into my working script

sed "s/Apple/__/g"
2
  • so add my new sed command before the original sed command with a temp output. but where we would i indicate the list2.txt Commented Nov 15, 2018 at 0:11
  • 1
    sed -e "s/Pie/$i/g" -e "s/Apple/__/g" old_script.sh > new_script.$i.sh (note: each expression is preceded by -e) Commented Nov 15, 2018 at 0:17

1 Answer 1

1

sed allows several ways to supply multiple commands. You can give them individually with -e or just write them into a single script string.

GNU sed allows commands on the same line to be separated with semicolons, and is genrally what you will find, but if you don't have that version you can use embedded newlines. As long as it's quoted it will work fine.

sed "s/Pie/$i/g; s/Apple/__/g;" old_script.sh # GNU specific but common

or

sed "
  s/Pie/$i/g
  s/Apple/__/g
" old_script.sh # general, should always work.

These are both valid.

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

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.