How do we use multiple commands with AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do we use multiple commands with AWK
# 1  
Old 04-14-2010
How do we use multiple commands with AWK

Hi,
I have a scenario where in, I have a file named abc.txt.
I extract the file names from it using.

Code:
 
awk '/dbf$/{print $NF}' abc.txt
/u01/oradata/omc/systab/omcdef.dbf
/u01/oradata/omc/oratemp/temptab1.dbf


Now I need to further enhance this command and also extract the mount point details using df -k

Eg. The final out put should be like
Code:
 
The mount point details for '/u01/oradata/omc/systab/omcdef.dbf' are:
 
/u01/oradata/omc/systab (/dev/vx/dsk/omcdg/systab_v) : 15080098 total allocated Kb
9728233 free allocated Kb
5351865 used allocated Kb
35 % allocation used
 
 
The mount point details for '/u01/oradata/omc/oratemp/temptab1.dbf' are:
 
/u01/oradata/omc/oratemp (/dev/vx/dsk/omcdg/oratemp_v) : 11305721 total allocated Kb
3429324 free allocated Kb
7876397 used allocated Kb
69 % allocation used

How do I achieve this with AWK?
# 2  
Old 04-14-2010
Use Following :

Code:
for i in `awk '/dbf$/{print $NF}' abc.txt`
do
Dev=`df -k $i|sed 1d|awk '{print $6}'`
Tot=`df -k $i|sed 1d|awk '{print $2}'`
Free=`df -k $i|sed 1d|awk '{print $4}'`
Used=`df -k $i|sed 1d|awk '{print $3}'`
Per=`df -k $i|sed 1d|awk '{print $5}'`
echo "The mount point details for $i are :"
echo " $i      ( $Dev )       :      $Tot  total allocated kb "
echo " $Free free allocated Kb "
echo "$Used  used allocated Kb"
echo "$Per % allocation used"
done


Hope this helps...
# 3  
Old 04-14-2010
Using an array to minimize the calls to awk :
Code:
#!/bin/bash
for F in $(awk '/dbf$/{print $NF}' abc.txt)
do
    A=( $(df -k $F | sed 1d) )
    echo "The mount point details for $F are :"
    echo "$F      ( ${A[5]} )       :      ${A[1]}  total allocated kb"
    echo "${A[3]} free allocated Kb"
    echo "${A[2]} used allocated Kb"
    echo "${A[4]}% allocation used"
done

# 4  
Old 04-15-2010
Thanks frans,
will check it also...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Pass Multiple Commands and Open Multiple Xterms via PSS

Hello, I'm attempting to open multiple xterms and run a command as an SAP user via sudo using PSSH. So far, I'm able to run PSSH to a file of servers with no check for keys, open every xterm in to the servers in the file list, and SUDO to the SAP(ADM) user, but it won't do anything else... (11 Replies)
Discussion started by: icemanj
11 Replies

2. Shell Programming and Scripting

Combine multiple awk commands

Hi Team, I am getting input like below $ ps -ef | grep pmon | grep -v asm | grep -v grep oracle 3246 1 0 00:03 ? 00:00:01 ora_pmon_racora1 oracle 4367 1 0 00:03 ? 00:00:01 ora_pmon_test1 oracle 6893 1 0 00:03 ? 00:00:01 ora_pmon_gipora1... (6 Replies)
Discussion started by: kamauv234
6 Replies

3. Shell Programming and Scripting

Get multiple values from an xml file using one of the following commands or together awk/perl/script

Hello, I have a requirement to extract the value from multiple xml node and print out the values to new file to compare. Would be done using either awk/perl or some unix script. For example sample input file: ..... ..... <factories xmi:type="resources.jdbc:DataSource"... (2 Replies)
Discussion started by: slbmind
2 Replies

4. Shell Programming and Scripting

Variables into SED or AWK and multiple commands

Hello I am hoping you may help. I am not sure how to go about this exactly, I know the tools but not sure how to make them work together. I have two SED commands that I would like to run in a shell script. I would like to take the manual input of a user (types in when prompted) to be used... (4 Replies)
Discussion started by: lostincashe
4 Replies

5. Shell Programming and Scripting

perform 3 awk commands to multiple files in multiple directories

Hi, I have a directory /home/datasets/ which contains a bunch (720) of subdirectories called hour_1/ hour_2/ etc..etc.. in each of these there is a single text file called (hour_1.txt in hour_1/ , hour_2.txt for hour_2/ etc..etc..) and i would like to do some text processing in them. Each of... (20 Replies)
Discussion started by: amarn
20 Replies

6. Shell Programming and Scripting

multiple commands

Hi, I have a flat file with delimitor as X'1F' Need to get a string from second line, third field. I have problem with the below command. Below command is not correct. value=`head -2 $file_name|tail -1|cut -f3 -d`echo -e "\037"`` problem is with ` please help me to resolve this. Is there... (5 Replies)
Discussion started by: rohan10k
5 Replies

7. Shell Programming and Scripting

Multiple awk commands with some formatting

Hi, I am trying to extract data from output files. I have three awk commands that can be used. All the three commands works separately. The second and third are similar as it outputs 'line 3' and 'line 13' after the common 'string' (I do not know how to combine them). I would like to get the... (4 Replies)
Discussion started by: p_sun
4 Replies

8. Solaris

Help with executing multiple remote commands after multiple hops

Hi SSHers, I have embedded this below code in my shell script.. /usr/bin/ssh -t $USER@$SERVER1 /usr/bin/ssh $USER2@S$SERVER2 echo uptime:`/opt/OV/bin/snmpget -r 0 -t 60 $nodeName system.3.0 | cut -d: -f3-5` SSH to both these servers are public-key authenticated, so things run... (13 Replies)
Discussion started by: LinuxUser2008
13 Replies

9. Shell Programming and Scripting

multiple commands

Hi, I have multiple commands that i need to run daily on my Solaris servers and watch the output, and actually i do it as multi-tasking. I do not want to put all of them in the file, and run it, and get the entire output at one time. What i want is that it should ask for before it runs next... (5 Replies)
Discussion started by: john_prince
5 Replies

10. Shell Programming and Scripting

How to do multiple commands:

NEVERMIND figured it out! (1 Reply)
Discussion started by: llsmr777
1 Replies
Login or Register to Ask a Question