get data from .txt file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users get data from .txt file
# 1  
Old 09-07-2006
get data from .txt file

Hi

I have a file diskspace.txt
the data in that file is asFilesystem kbytes used avail %used Mounted on
/dev/vg06/lvol1 18870272 12099836 6673336 64% /dist

know i am writing a script to get the above bold data and that data need to be used as a input.

any idea...
# 2  
Old 09-07-2006
I can give you what you want with awk - this gives you the 64% from the second line
Code:
awk '{ if(NR==2){ print $5; exit }}' diskspace.txt | read diskused
#the variable diskused now equals "64%", so what do you want to do next?
myscript.sg $diskused

this passes it as a parameter to myscript.sh
# 3  
Old 09-08-2006
Cont..

Thanks for ur kind reply.. it works...

Now i want to collect that value '64%' and write the if condition, like to write a script to send a mail if when the value is '>95'.

how can i do that..

can someone please correct below:

bdf /dist | awk '{ if(NR==2){ print $5 }}'
if [ $? -ge 95% ]
then
echo "hi there more than 95%" | mailx -r 'xyz' -s '> 95%' xyz@abc.com
else
echo "Disk Space less than < 95%"

Thanks..

Last edited by gkrishnag; 09-08-2006 at 04:16 AM..
# 4  
Old 09-08-2006
Need script correction

Code:
bdf /dist | awk '{ if(NR==2){ print $5 }}'
if [ "$?" -ge "95%" ];
then
echo "hi Diskspace is more than 95" | mailx -r 'Hello' -s 'Diskspace-95%' xyz@abc.com && bdf /dist | awk '{ if(NR==2){ print $5 }}'
else
echo "Disk Space less than 95%" && bdf /dist | awk '{ if(NR==2){ print $5 }}'
fi

I am getting result as:
findlog.sh[11]: 95%: Expression is not complete; more tokens expected.
Disk Space less than 95%
70%

I am getting the same result though greater 95 or less than 95

can some one tell me why?

Last edited by blowtorch; 09-08-2006 at 07:01 AM.. Reason: add code tags
# 5  
Old 09-08-2006
Hello!? You are checking for $? which is the return code from the previous command. Not what you want. Most commands return 0 when successful.

What you actually want is the percent space occupied... use this:
Code:
#!/usr/bin/ksh
#set -x
host=$(uname -n)
PATH=/usr/bin
Threshold=95

bdf|tail +2|awk '{print $6,$5}'|while read fs pctused; do
if [ "${pctused%%\%}" -gt $Threshold ]; then
        echo $fs on $host above $Threshold - at $pctused
else
        echo $fs on $host at $pctused
fi
done

Only, instead of echo, use your mailx to send mail.

-Edit
Your threads were about the same subject so I've merged them.
-/Edit

Last edited by blowtorch; 09-08-2006 at 07:18 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy data to CSV file from txt output

Hi Everyone , Below is output from a TL1 , I want just the NE Name: and beside that the Temperature and the voltages in a csv file , Is this possible? > act-user:AB1S2a:ArshadFO:493::**********; AB1S2a 2016-02-07 10:13:24 M 493 COMPLD "ArshadFO:2016-02-07 10-04-55,0" ;... (11 Replies)
Discussion started by: adgjmpt
11 Replies

2. Shell Programming and Scripting

Removing inline binary data from txt file

I am trying to parse a file but the filehas binary data inline mixed with text fields. I tried the binutils strings function , it get the binary data out but put the char following the binary data in a new line . input file app_id:1936 pgm_num:0 branch:TBNY ord_num:0500012(–QMK) deal_num:0... (12 Replies)
Discussion started by: tasmac
12 Replies

3. Shell Programming and Scripting

Data extraction from .txt file

Hey all, i´ve got the following problem: i´m aquiring data with an instrument and i get data in a .txt file. This is how the txt file looks like: Report of AU program poptau F1P=-49.986ppm F2P=-110.014ppm Target directory for serfile: D:/data/Spect500/nmr/Thoma/882 Linear... (17 Replies)
Discussion started by: expikx
17 Replies

4. Shell Programming and Scripting

create txt file form data file

File A.txt LL07 LL07_B_1 20 LL85 LL85_A_1 40 LL85 LL85_B_1 40 LL85 LL85_C_1 30 LL37 LL37_A_1 60 LL37 LL37_B_1 20 LL37 LL37_C_1 50 I want cretae diffrent tex file base of above file Should be threee text file LL07.txt LL85.txt LL37.txt Eaach text file have below data... (2 Replies)
Discussion started by: asavaliya
2 Replies

5. Shell Programming and Scripting

create txt file form data file and add some line on it

Hi Guys, I have file A.txt File A Data AK1521 AK2536 AK3164 I want create text file of all data above and write some data on each file. want Output on below folder /home/kka/out AK1521.txt Hi Welocme (3 Replies)
Discussion started by: asavaliya
3 Replies

6. Shell Programming and Scripting

Get Data From CSV File and put into a txt file

Hi Guys, File A I have File A as CSV Format.... No R SS MK Par value S AL A1 PKL123 Lo12 1 S AL A2 PKl123 Lo34 22 S AL A3 PkLK234 Lo67 -34 S AL A4 PkLK235 Lo09 120 S AL A5 PkLK236 Lo76 19 S AL A6 PkLK237 Lo44 -17 S AL A7 PkLK238 Lo90 2 S AL A8 PkLK239 Lo34 -9 I want file B like... (4 Replies)
Discussion started by: asavaliya
4 Replies

7. Shell Programming and Scripting

RegeX to parse data from a txt file

Hi all the experts out there, I am totally new to perl and I was given an assignment by using Perl to find the 2nd element of each line in each curly bracket which made up of 5 elements. Expected result should like this: Type: VCC Pin_name: AK32,AL32,AH21,..... Type: NC Pin_name:... (2 Replies)
Discussion started by: killbanne
2 Replies

8. Shell Programming and Scripting

Want to read data from a file name.txt and search it in another file and then matching...

Hi Frnds... I have an input file name.txt and another file named as source.. name.txt is having only one column and source is having around 25 columns...i need to read from name.txt line by line and search it in source file and then save the result in results file.. I have a rough idea about the... (15 Replies)
Discussion started by: ektubbe
15 Replies

9. Shell Programming and Scripting

shellscript to read data from txt file and import to oracle db

Hi all, Help needed urgently. I am currently writing a shellscript to read data/record from a flat file (.txt) file, and import/upload the data to oracle database. The script is working fine, but it takes too long time (for 18000 records, it takes around 90 mins). I guess it takes so long... (1 Reply)
Discussion started by: robot_mas
1 Replies

10. Shell Programming and Scripting

unix script to takes the old data from a TXT file and compress them into new file

Hi, I am looking for the unix script which can takes the 2 month old data from a TXT file (there is one txt file in whiche messages are appended on daily basis) and compress them into new file.Please halp me out. (2 Replies)
Discussion started by: vpandey
2 Replies
Login or Register to Ask a Question