Home > Blockchain >  Windows script replace entire line
Windows script replace entire line

Time:02-01

On a windows script i need to replace entire line number of a file (eg: line number 15) with the contents of a variable. I don´t have a string to search for it will depend of the file but the line number is always the same. The file in question is of type xml, if necessary i can install any tool that could help me doing this using the windows scripting.

I am out of options, once i see many options of achieving this on linux but not on windows. Already tried find and replace but since my files are different i don´t have a search pattern

CodePudding user response:

As you seem in dire straits, there are standalone versions the unix/linux sed utility for windows you can install without requiring cygwin or MSYS2 etc.

Sorry, I can't provide a link. It will be better for you to search as you're aware of your local OS version and any other details that might impact which version you select.

But

 echo "1
> 2
> 3
> 4" | sed '3s/.*/Something/'

output

1
2
Something
4

Shows one approach.

IHTH

  • Related