3

I have a big file (50G) and I would like to replace the lines starting with the content of variable $i with content of variable $newline using parallel command.

My script is given below

#!/bin/sh 
File="test.txt"
i="foo"
newline="helooooooo"

parallel -a $File -k --block 30M --pipe-part 'sed -i /^$i/d' $File
echo $newline >> $File 

It's not working for me, just deleting the line only.

1
  • What's the idea here in using parallel, why not just use sed to do all this by itself? Commented Aug 1, 2018 at 9:13

1 Answer 1

4

I think your issue is here:

'sed -i /^$i/d'

Try this:

"sed -i /^$i/d"

The variable $i cannot get expanded because it's wrapped in single quotes, switching these to double quotes allows Bash to expand them with your variable $i.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.