awk {print $NF} output??

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers awk {print $NF} output??
# 1  
awk {print $NF} output??


I am trying to debug an old script and have found the problem lies within this function:

isIdoc() { # validate the file type
fileType=`file $1 | awk '{print $NF}'`
[ $fileType = "IDOC" ] && echo 0 || echo 1

My question is, how can I determine what is in the variable $fileType ? The program is failing only randomly, but I cannot modify the script (yet), so I need to know what value is being tested to "IDOC"... i'm not so sure what data is coming out of awk '{print $NF}'.

Thanks for any help...

# 2  
awk $NF prints only the last column in a record. If the file has only one row,
your variable will contain whatever is in the last column (space/tab delimiter).

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #901
Difficulty: Easy
Steve Jobs offered Linus Torvalds a job in 2000, on the condition that he stopped development on Linux.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print commas between awk output

When I output fields 1 2 4 5 & 6, I would like to have a comma between them but I am beating my head against the wall to get it to work. Any help is appreciated sed 's/]*,]*/,/g' file1 > file1.$$ && awk -F, 'FNR==NR{f2=$1 $2 $4 $5 $6;next} FNR==1{print $0, "CDP NE Hostname,CDP NE IP,Remote... (6 Replies)
Discussion started by: dis0wned
6 Replies

2. Shell Programming and Scripting

Using awk to print output based on first field.

Hi Folks, I have one requirement, There is one file, which contains two fields. Based on first field, I need to print an output. Example will be more suitable. Input file like this. abc 5 abc 10 xyz 6 xyz 9 xyz 10 mnp 10 mnp 12 mnp 6 (2 Replies)
Discussion started by: Raza Ali
2 Replies

3. Shell Programming and Scripting

Print awk output in same line ,For loop

My code is something like below. #/bin/bash for i in `ps -ef | grep pmon | grep -v bash | grep -v grep | grep -v perl | grep -v asm | grep -v MGMT|awk '{print $1" "$8}'` do echo $i ORACLE_SID=`echo $line | awk '{print $2}'` USERNAME=`echo $line | awk '{print $1}'` done ============= But... (3 Replies)
Discussion started by: tapia
3 Replies

4. Shell Programming and Scripting

awk print output problem

Hello friends, I have written a script and i need to add some part into it so that i could print out more results depending on more conditions, This is the core part of the script which does the actual work: echo "$j" && nawk -v stat=$2 'NR==FNR &&... (1 Reply)
Discussion started by: EAGL
1 Replies

5. UNIX for Dummies Questions & Answers

Any awk one liner to print df output?

Hi, OS = Solaris Can anyone advise if there is a one liner to print specific output from a df -k output? Running df from a command line, it sometimes gives me 2 lines for some volume. By re-directing the output to a file, it always gives 1 line for each. Below is an example output,... (4 Replies)
Discussion started by: newbie_01
4 Replies

6. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

7. Shell Programming and Scripting

awk command : To print the output to a file

half of the problem is already solved with the help of bartus11 suggestion I have a txt file having rows and coulmns, i want to perform some operation on a specific coulmn starting from a specific line. 50.000000 1 1 1 1000.00000 1000.00000 ... (5 Replies)
Discussion started by: shashi792
5 Replies

8. Shell Programming and Scripting

awk subtraction and print output

FileA F97S 83 530 K569E 531 736 output shud be F16S K40E it is code sed 's///g' FileA |awk '{print $1-$2+2}' it will print 16 40 anything can come with this output?? (1 Reply)
Discussion started by: cdfd123
1 Replies

9. Shell Programming and Scripting

using perl or awk to print output

suppose u have file File A A -> G C->D A -> R P->A File B A=1 C=2 D=3 E=4 F=5 G=6 H=7 I=8 K=9 L=10 M=11 (5 Replies)
Discussion started by: cdfd123
5 Replies

10. Shell Programming and Scripting

using awk to search and print output

suppose i have one file file A 18 24 30 35 38 45 55 Another file file B 08_46 A 16 V -0.36 0.23 E : 1.41 08_46 A 17 D -1.04 0.22 E : 0.84 08_46 A 18 Q -0.49 0.12 E : 0.06 08_46 A 19 G 0.50 0.14 E : 0.05 08_46 A 20 V ... (5 Replies)
Discussion started by: cdfd123
5 Replies

Featured Tech Videos