I have a text file with the following information:
Filesystem Use%
/dev/sda1 44%
/dev/sda7 35%
/dev/sda3 2%
/dev/sda2 5%
/dev/sda5 47%
tmpfs 0%
Now, I want to make a batch file that reads this text file, store the numbers of the lines 2,3,4,5 e 6 into some variables and then compare these numbers with a specific value set by me. The comparison would be something like this:
variable = 44
if variable > 90
then it presents a console message whith the all the line of the variable stored.
variabletwo =35
if variabletwo > 90
then it presents a console message whith the all the line of the variable stored.
and so on...
Can someone help me please?
bash script that reads a txt file,stores the numbers within
Moderator: DosItHelp
-
- Posts: 2
- Joined: 08 Nov 2013 07:10
Re: bash script that reads a txt file,stores the numbers wit
I'm not sure you replied on StackOverflow but I didn't get an alert.
This will currently report the lines that exceed 30.
This will currently report the lines that exceed 30.
Code: Select all
@echo off
for /f "delims=%%" %%a in ('find "/" ^< "file.txt" ') do (
for /f "tokens=1,2" %%b in ("%%a") do (
if %%c GTR 30 echo %%a%%
)
)
pause
-
- Posts: 2
- Joined: 08 Nov 2013 07:10
Re: bash script that reads a txt file,stores the numbers wit
Hi foxidrive,thanks in advance.
I tested your code and it works
But, can you explain me what it does the following part:
'find "/" ^< "disk.txt" ' -> I understand that you search for the first "/" but then what do you do? do you add a % character?
I tested your code and it works

'find "/" ^< "disk.txt" ' -> I understand that you search for the first "/" but then what do you do? do you add a % character?
Re: bash script that reads a txt file,stores the numbers wit
The top for loop removes the percent sign, and filters for all lines that contain a / character anywhere in the line.
The second for loop takes each line in turn, and separates the first term and the number (using space as a default delimiter) and then compares the number.
If it matches then the echo displays the content of %%a and adds a % sign at the end (which needs two %% to create a % sign).
The second for loop takes each line in turn, and separates the first term and the number (using space as a default delimiter) and then compares the number.
If it matches then the echo displays the content of %%a and adds a % sign at the end (which needs two %% to create a % sign).