Visit The New, Modern Unix Linux Community


awk command : To print the output to a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk command : To print the output to a file
# 1  
Question 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.
Code:
50.000000               1           1           1
  1000.00000    
  1000.00000    
   50000.000    
     19
     19
  3.69797533E-07   871.66394       36.611320      -12.000000      -35.290180          4      5
  1.13238150E-06   879.03741       36.047676      -10.800000       38.395638          4      4
  6.69133044E-07   717.85254       34.777313      -9.1999998       24.722189          3      3
  8.59679221E-06   381.38339       33.485676      -8.0000000       14.840780          1      1
  5.23395693E-06   247.83061       33.334003      -5.5999999      -5.1661811          0      1
  6.89546050E-06   259.99509       33.329212      -5.1999998      -6.1069846          0      1

I want to select the data from 3rd coulmn from 7th line to end of clm. And find out the minimum and the maximum out of them.then calculate the difference between the min and max .
Code:
delay = max-min

and write "min" "max" "delay" to a txt file for further operation

Code:
awk 'NR==7{min=$3;max=$3}NR>7{if ($3>max){max=$3};if ($3<min){min=$3}}END{print "min: "min" max: "max}' file

I tried few options but it dosent work

Code:
awk 'NR==7{min=$3;max=$3} NR>7{if ($3>max){max=$3};if ($3<min){min=$3}}END delay=max-min {print "To: "min"  Tmax : "max"   delay= "delay }' seamount1.arr

# 2  
Umm a sintax error , try:
Code:
awk 'NR==7{min=$3;max=$3} NR>7{if ($3>max){max=$3};if ($3<min){min=$3}}END{delay=max-min; print "To: "min"  Tmax : "max"   delay= "delay }'

# 3  
still i'm getting an 'awk' syntax error
# 4  
r u on solaris? use then nawk..
# 5  
problem solved with the help of " bartus11 "

Code:
awk 'NR==7{min=$3;max=$3} NR>7{if ($3>max){max=$3};if ($3<min){min=$3}}END{delay=max-min;print "To: "min"  Tmax : "max" delay= "delay }' seamount1.arr

now everything works absolutely fine.
# 6  
Exactly the same i provided u ...

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

Test Your Knowledge in Computers #991
Difficulty: Medium
System V was known inside Bell Labs as Unix 6.0.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print field from lookup file in output

The below awk uses $3 and $4 in search as the min and max, then takes each $2 value in lookup and compares it. If the value in lookupfalls within the range in searchthen it prints the entire line in lookup/ICODE]. What I can't seem to figure out is how to print the matching $5 from search on that... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Print column details from fixed width file using awk command

hi, i have a fixed width file with multiple columns and need to print data using awk command. i use: awk -F "|" '($5 == BH) {print $1,$2,$3}' <non_AIM target>.txt for a delimiter file. but now i have a fixed width file like below: 7518 8269511BH 20141224951050N8262 11148 8269511BH... (5 Replies)
Discussion started by: kcdg859
5 Replies

3. Shell Programming and Scripting

Help needed with file output awk sed command - please

Hi I have a file that contains lines starting with a particular string plus a Colon: I need to output all these lines but only what comes after the colon Can you pelase assist? Example of lines in the file: com.ubs.f35.cashequities/cashequities: 1 2 ... (5 Replies)
Discussion started by: mnassiri
5 Replies

4. UNIX for Dummies Questions & Answers

taking the output of awk command to a new file

cat doc | nawk -v da="${date}" '$23>199 {print $0 > "doc"+da+".txt"}' Every time(need to run every day) i run this, i want to a create a new file "doc_01 Aug.txt". Basically, i want to create a new file with date appended in it. The above command is creating a file with name "0".... (4 Replies)
Discussion started by: vagar11
4 Replies

5. 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

6. Shell Programming and Scripting

awk to compare flat files and print output to another file

Hello, I am strugling from quite a some time to compare flat files with over 1 million records could anyone please help me. I want to compare two pipe delimited flat files, file1 with file2 and output the unmatched rows from file2 in file3 Sample File1: ... (9 Replies)
Discussion started by: suhaeb
9 Replies

7. UNIX for Dummies Questions & Answers

awk {print $NF} output??

Hi, 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}'` && echo 0 || echo 1 } My question is, how can I determine what is in the variable $fileType ? The program is... (1 Reply)
Discussion started by: vervette
1 Replies

8. Shell Programming and Scripting

To parse through the file and print output using awk or sed script

suppose if u have a file like that Hen ABCCSGSGSGJJJJK 15 Cock ABCCSGGGSGIJJJL 15 * * * * * * : * * * . * * * : Hen CFCDFCSDFCDERTF 30 Cock CHCDFCSDHCDEGFI 30 * . * * * * * * * : * * :* : : . The output shud be where there is : and . It shud... (4 Replies)
Discussion started by: cdfd123
4 Replies

9. UNIX for Dummies Questions & Answers

using awk or sed to print output from one file

dear i have one file regarding >abshabja>sdksjbs>sknakna>snajxcls so i want to be output like >abshabja >sjkabjb >sknakna >snajxcls Any using awk or sed will help thanks (2 Replies)
Discussion started by: cdfd123
2 Replies

Featured Tech Videos