Can I use columns from text files in if statements?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can I use columns from text files in if statements?
# 15  
Old 12-02-2010
Quote:
Originally Posted by Corona688
Whatever your first column is. In my example that's A, so "${A}".
Well the above I took from my dfcap.txt file had:

Used
2082764

And if this will be reading through, but since the numbers won't always be the same (because files get added, and the total user "Used Storage" changes, wouldn't this method only work if it I had a static number to use?

Right now I have

Code:
while read $CAP
do
if ( $CAP -lt [what goes here for my example] ) then
echo cat dfcap.txt
else
echo "No user usage exceeds this number"
fi
done

---------- Post updated at 07:56 PM ---------- Previous update was at 06:19 PM ----------

Ok I am this far, now i'm stuck again

Code:
df -k /home/* | grep -v "FileSystem" | awk '{print $3, $4, $1}' > dfcap.txt

echo -n "Enter a capacity in Kilobytes: "
read cap

space=`cat dfcap.txt | awk '{print $1}'`

for i in $space
do
if ( test $cap -gt $space ) then
echo "working"
else
echo "broken"
fi
done

sleep 7

right now when I enter a number I get

./option.sh: line 12: test: used: integer expression expected
brokeeen

./option.sh: line 12: test: used: integer expression expected
brokeeen

(yes, runs it twice). Any suggestions?
# 16  
Old 12-02-2010
if [[ $cap -gt $space ]]; then
# 17  
Old 12-02-2010
i made that change, now I am getting 2082772: syntax error in expressions (error token is "2082772")
brokeeen

the number 2082772 is in the text file which I am trying to use for my if statement. The broken and working parts are just for testing. Now I need to figure out this error.
# 18  
Old 12-03-2010
Quote:
Originally Posted by ninjafish
Well the above I took from my dfcap.txt file had:

Used
2082764

And if this will be reading through, but since the numbers won't always be the same (because files get added, and the total user "Used Storage" changes, wouldn't this method only work if it I had a static number to use?
It reads from the file, which you dumped current numbers into. Where would it magically get old numbers?

---------- Post updated at 02:18 PM ---------- Previous update was at 02:11 PM ----------

Please post your entire script as you have it now. Substitutions and half-fixes have been thrown all over the place, who knows what it actually looks like by now.
# 19  
Old 12-04-2010
Quote:
Originally Posted by ninjafish
i made that change, now I am getting 2082772: syntax error in expressions (error token is "2082772")
brokeeen

the number 2082772 is in the text file which I am trying to use for my if statement. The broken and working parts are just for testing. Now I need to figure out this error.
Did you copy paste the suggested line or did you add some quote around the variables ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Separate columns into different text files

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)
Discussion started by: my_Perl
2 Replies

2. Shell Programming and Scripting

Comparing columns in 2 text files

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)
Discussion started by: Shyam_84
9 Replies

3. Programming

Read columns from text files

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)
Discussion started by: emily
2 Replies

4. UNIX for Dummies Questions & Answers

Splitting up a text file into multiple files by columns

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)
Discussion started by: evelibertine
1 Replies

5. UNIX for Dummies Questions & Answers

Merging two text files by two columns

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)
Discussion started by: evelibertine
4 Replies

6. UNIX for Dummies Questions & Answers

Removing columns from a text file that do not have any values in second and third columns

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)
Discussion started by: evelibertine
3 Replies

7. UNIX for Dummies Questions & Answers

Combining two text files as columns?

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)
Discussion started by: evelibertine
1 Replies

8. Shell Programming and Scripting

Compare Fields from two text files using key columns

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)
Discussion started by: Sangtha
2 Replies

9. Shell Programming and Scripting

merging few columns of two text files to a new file

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)
Discussion started by: kolvi
4 Replies

10. UNIX for Dummies Questions & Answers

searching text files on specific columns for duplicates

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)
Discussion started by: Gerry405
2 Replies
Login or Register to Ask a Question