I'm not to great with loops atm. I am wondering what
will do?
imagine it's reading from this file:
read splits apart into different variables based on the IFS variable. If you leave IFS alone, it splits text apart on spaces and tabs. It will split properly even given multiple spaces, so your tr -s may be redundant now.
The first loop, it will set A=a, B=b, C=c, D=d, E=e, F=f, G=g.
Second loop, A=h, B=i, C=j, D=k, E=l, F=m, G=n
Third loop, A=o, B=p, C=q, D=r, E=s, F=t, G=u
Fourth loop, A=v, B=w, C=x, D=y, E=z, F=1, G=2
...and then the loop breaks, because read hits the end of file and returns a nonzero value.
At the bottom of the loop, after the do, is where we tell it to read the file, with < df.txt You can redirect files into entire loops, not just single statements, that's one of the really useful things about a shell language.
imagine it's reading from this file:
read splits apart into different variables based on the IFS variable. If you leave IFS alone, it splits text apart on spaces and tabs. It will split properly even given multiple spaces, so your tr -s may be redundant now.
The first loop, it will set A=a, B=b, C=c, D=d, E=e, F=f, G=g.
Second loop, A=h, B=i, C=j, D=k, E=l, F=m, G=n
Third loop, A=o, B=p, C=q, D=r, E=s, F=t, G=u
Fourth loop, A=v, B=w, C=x, D=y, E=z, F=1, G=2
...and then the loop breaks, because read hits the end of file and returns a nonzero value.
At the bottom of the loop, after the do, is where we tell it to read the file, with < df.txt You can redirect files into entire loops, not just single statements, that's one of the really useful things about a shell language.
Will that work if I am trying to compare it to the numbers?
Or would I need to go with
Will that work if I am trying to compare it to the numbers?
Or would I need to go with
or will the first one work fine for it?
You already used read. Don't try and confuse yourself, it's not doing anything different than last time.
Read takes variable names. It'll happily put any text in any variable. It doesn't care a thing about numbers. Once you've read into VAR, you use it like $VAR.
But, you can't name a variable a number, but that's a limit of the shell, not a limit of read.
Call the columns something descriptive like DIR or SIZE or what have you so you can understand your own script later.
You already used read. Don't try and confuse yourself, it's not doing anything different than last time.
Read takes variable names. It'll happily put any text in any variable. It doesn't care a thing about numbers. Once you've read into VAR, you use it like $VAR.
But, you can't name a variable a number, but that's a limit of the shell, not a limit of read.
Call the columns something descriptive like DIR or SIZE or what have you so you can understand your own script later.
Then to compare a number
Right now this is what comes out for my dfcap.txt:
Used Available FileSystem
20082764 982120 /dev/mapper/live-rw
Assuming I want to compare $capacity to the firs collumn numbers, which are 2082764, what would go into the latter argument in my if statement.
ya, sorry for the misspelling ni the code, however the part i'm having difficulty with is after
if ($cap -gt [ ])
i don't know what should go into those square brackets. I don't know what argument will let me grab the text out of the df.txt file to compare it, then output anything that is greater then whatever the $cap variable was given.
you still miss a space after the ( and before the )
you still miss a space after the ( and before the )
Those small details I am not concerned about. Right now I am just trying to get the proper syntax which will accept my if statement and return a value. I can clean up lack of spaces, etc, when I get it working.
Hi
I have large text file consisting of five columns. Sample of the file is give below:
ed 2-4 12.0 commons that they depended on. मानवों नष्ट किया जिन पर वो आधारित थे।
ed 3-1 12.0 Almost E, but would be over. रचना करीब करीब ई तक जाती है, मगर तब तो नाटक ख़त्म हो... (2 Replies)
Hi
i have 2 files
file1.txt
XX,ZZ,XC,EE,RR,BB
XC,CF,FG,RG,GH,GH
File2.txt
DF,GH,MH,FR,FG,GH,NOTOK
XX,ZZ,XC,EE,RR,BB,OK
result
XX,ZZ,XC,EE,RR,BB OK
look for column1 , XX and if it matches in File2.txt , retrieve the 7 th field from File2 and print in 3 rd file , ... (9 Replies)
Dear All,
I have basic structure of the C++ code . It suppose to read particular columns from some txt file. The txt file look like following (snippet). I have to ask the details for instance 'id' information for rows satisfying text with red color. The issue is that the txt file has not just the... (2 Replies)
Hi,
I have a space delimited text file with multiple columns 102 columns. I want to break it up into 100 files labelled 1.txt through 100.txt (n.txt). Each text file will contain the first two columns and in addition the nth column (that corresponds to n.txt). The third file will contain the... (1 Reply)
Hi,
I have two text files that I would like to merge/join. I would like to join them if the first columns of both text files match and the second column of the first text file matches the third column of the second text file.
Example input:
First file:
1334 10 0 0 1 5.2
1334 12 0 0 1 4.5... (4 Replies)
I have a text file that has three columns. But at the end of the text file, there are trailing lines that have missing second and third columns:
4 0.04972604 KLHL28
4 0.0497332 CSTB
4 0.04979822 AIF1
4 0.04983331 DECR2
4 0.04990344 KATNB1
4
4
4
4
How can I remove the trailing... (3 Replies)
I have one space delimited file with multiple columns and one tab delimited file with multiple columns (They have the same number of rows). I want to basically combine these two text files into a new text file by column. How would I go about doing that? (1 Reply)
Hi All,
I have two files to compare. Each has 10 columns with first 4 columns being key index together. The rest of the columns have monetary values.
Using Perl, I want to read one file into hash; check for the key value availability in file 2; then compare the values in the rest of 6... (2 Replies)
hi
i need to select a few columns of two txt files and write it to a new file. there is one common field for both of these files.
plz help me in this
thanks in advance (4 Replies)
Is it possible to search through a large file full of rows and columns of text and retrieve only the rows that contain duplicates fields,
searchiing for duplicates on col4 & col6
Sample below
Col1 col2 col3 col4 col5 col6
G405H SURG FERGUSON ... (2 Replies)