# Batch file issues



## lammv (Aug 19, 2012)

Hello there.
I 'm trying to solve one issue.

1. I have a file names.ini. The end of the file is:


```
FOV=15
[Network] 
Networkline=default
```
Here I need to change FOV and two last lines leave the same. So I use the FINDSTR.
The easiest way for me is finding lines which contain words " network fov", delete them and then add to the file following lines


```
echo FOV=%m% >> names.ini
echo [Network] >> names.ini
echo Networkline=default >> names.ini
```
so. FIND and DELETE.

I've found how to FIND


```
sc query | findstr /i "network fov" names.ini  ?????
```
how to delete the founded lines?

2. And for sure.
what is the command here just replacing FOV with its new value


```
sc query | findstr  "FOV" names.ini  ?????
```
how to replace the founded line by the new FOV's value?
3. Also I have a line in the names.ini file
NAME=changed_username

I can find it by means of the line too. 
But how can I read it and use it in my next operations?


```
sc query | findstr "FOV" names.ini   ????
```


----------



## Squashman (Apr 4, 2003)

Well your syntax isn't even close if you were using quarter stick of TNT to try and accomplish this task.

Let me see the output of 

```
sc query | findstr /C:"FOV"
```


----------



## lammv (Aug 19, 2012)

Can you be more specific, because the issue doesn't work so far.
I brought up 3 questions.
Can I get back 3 lines of your answers?
Thank you.


----------



## Squashman (Apr 4, 2003)

I can't answer any of your questions until you show me the output of

```
sc query | findstr /C:"FOV"
```
From what I understand you are trying to update the "names.ini" file with output from the "SC QUERY" command.

If you cannot answer my questions then I cannot answer yours.


----------



## bliss-II (Oct 18, 2012)

```
sc query | findstr /c:"FOV" >> tempfile
for /f "skip=1 tokens=1" %%a in (names.ini) do echo %%a >> tempfile
del names.ini
ren tempfile names.ini
```
The FOR loop basically skips the first line and dumps the rest into tempfile.

The rest should be self-explanatory.


----------



## foxidrive (Oct 20, 2012)

This should do it too and uses GNUsed for Windows.

It expects that FOV=NNN only appears once in the output from SC query and it is designed to replace the entire line when FOV= appears in the first column of names.ini

I can't check the format of FOV=NNN from sc query as it doesn't appear on my machine.


```
@echo off
for /f "delims=" %%a in ('sc query ^| findstr /c:"FOV"') do (
sed "s/^fov=.*$/%%a/I" names.ini >names.ini.tmp
)
move /y names.ini.tmp names.ini
```
Thanks to squashman for pointing out the forum - another one for me to play in.


----------

