Skip to content
Advertisement

Sed to replace a speccificc part of line by argument in shell script based in line number

I have a script test.sh
He has some arguments like :

JavaScript

I made a while read loop to replace each specific part of a line (extractReplaceArgLine) with argument passed in shell script (Forest Cuba World Hello).

JavaScript

Consider the file test.txt :

JavaScript

So, the output would be :

JavaScript

How can I do that ?

Thanks !

Advertisement

Answer

Use $1 to get the first argument, and then use shift to shift the arguments down. Doing this in a loop will process each argument in sequence.

There’s also no need to use cut and sed, you can use the shell’s built-in operations.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement