Sponsored Content
Top Forums Shell Programming and Scripting sort, columns, no result! can I print files of "planes"? Post 302564585 by mirni on Friday 14th of October 2011 06:26:31 AM
Old 10-14-2011
Using awk is probably the easiest way. It handles floating point arithmetics well (whereas bash doesn't):

Code:
$ cat input
-0.012    0.0060    0.0    0.13972813076023477    
-0.012    0.0064319163    4.2894483E-4    0.1959584596359705    
-0.011398672    0.00644576    0.0    0.20924591828425124    
-0.012    0.0068638325    8.5788965E-4    0.19486370704346412
-0.9	  0.5555	  1.0024	  944
0.9	  33		  100.7E-2     blah	
someValue 2ndCol	  -20.098e-1	  YES!
$ for z in -2 -1 0 1 2 ; do 
> echo "================ z=$z ==========" 
> awk -v"z=$z" '$3>z-0.05 && $3<z+0.05' input 
> done
================ z=-2 ==========
someValue 2ndCol	  -20.098e-1	  YES!
================ z=-1 ==========
================ z=0 ==========
-0.012    0.0060    0.0    0.13972813076023477    
-0.012    0.0064319163    4.2894483E-4    0.1959584596359705    
-0.011398672    0.00644576    0.0    0.20924591828425124    
-0.012    0.0068638325    8.5788965E-4    0.19486370704346412
================ z=1 ==========
-0.9	  0.5555	  1.0024	  944
0.9	  33		  100.7E-2	  blah
================ z=2 ==========

I use awk's -v switch to set the variable "z", and then outer shell loop to loop through it. Although you could as well (actually more efficiently) do the outer z loop within awk itself. The awk command is just the condition; which results in printing the line that fullfills the condition.
You can then easily redirect the output to a file, and sort the output files, if you like.
I have a feeling you can figure out the rest yourself, but if you need help, feel free to ask.

Last edited by mirni; 10-14-2011 at 07:35 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

2. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

3. Solaris

How to check "faulty" or "stalled" print queues - SAP systems?

Hi all, First off, sorry for a long post but I think I have no other option if I need to explain properly what I need help for. I need some advise on how best to check for "faulty" or "stalled/jammed' print queues. At the moment, I have three (3) application servers which also acts as print... (0 Replies)
Discussion started by: newbie_01
0 Replies

4. Shell Programming and Scripting

Meaning of "b" modifier in "sort" command

I need to sort the following file by the rhdiskpower devices in the last column: Total_MB Free_MB OS_MB Name Failgroup Library Label UDID Product Redund Path 1024 851 1024 OCRVOT1_0000 OCRVOT1_0000 System UNKNOWN ... (3 Replies)
Discussion started by: wjssj
3 Replies

5. Shell Programming and Scripting

Awk find in columns with "if then" statement and print results

I have a file1.txt file1.txt F-120009210","Felix","U-M-F-F-F-","white","yes","no","U-M-F-F-F-","Bristol","RI","true" F-120009213","Fluffy","U-F-","white","yes","no","M-F-","Warwick","RI","true" U-120009217","Lity","U-M-","grey","yes","yes","","Fall River","MA","true"... (4 Replies)
Discussion started by: charles33
4 Replies

6. UNIX for Dummies Questions & Answers

Sorting files ending in numbers with "sort"

I have a group of files that I need to be sorted by number. I have tried to use the sort command without any luck. ls includes* includes1 includes10 includes11 includes12 includes2 includes3 includes4 includes5 includes6 includes7 includes8 includes9 I have tried ls includes*... (6 Replies)
Discussion started by: newbie2010
6 Replies

7. UNIX for Beginners Questions & Answers

Extract delta records using with "comm" and "sort" commands combination

Hi All, I have 2 pipe delimited files viz., file_old and file_new. I'm trying to compare these 2 files, and extract all the different rows between them into a new_file. comm -3 < sort file_old < sort file_new > new_file I am getting the below error: -ksh: sort: cannot open But if I do... (7 Replies)
Discussion started by: njny
7 Replies

8. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

9. UNIX for Beginners Questions & Answers

How to use "awk" to print columns from different files in separate columns?

Hi, I'm trying to copy and paste the sixth column from a bunch of files into a single file having each column pasted in separate columns (and not one after each other in just one column.) I tried this code but works only partially because it copied and pasted 50 rows of each column... (6 Replies)
Discussion started by: Frastra
6 Replies

10. UNIX for Beginners Questions & Answers

How to print the "grep" result as specified keyword order?

I have a content.xls file as given below, NC_020815.1 1891831 1894692 virb4_A0A0H2X8Z4_ 1 954 1945 NC_020815.1 1883937 1886123 vird4_A0A0P9KA26_ 1 729 1379 NC_020815.1 2976151 2974985 virb10_H8FLU5_Ba 1 393 478 NC_020815.1 2968797 2967745 virb6_A0A0Q5GCZ4 5 398 499... (2 Replies)
Discussion started by: dineshkumarsrk
2 Replies
GPIV_NSTRAIN(1) 					      General Commands Manual						   GPIV_NSTRAIN(1)

NAME
gpiv_nstrain - Calculates normal strain from PIV data. SYNOPSIS
gpiv_nstrain [-d N] [-h | --help] [-p | --print] [-g | --g] [--no_g ] [-v | --version] [filename] < stdin > stdout DESCRIPTION
gpiv_nstrain calculates the normal strain from PIV data. You can choose from several differential schemes: central differentiation, least squares, and Richardson extrapolation. The output can be generated as ASCII data containing four columns or as GNUPlot Data format that allows one to view/print the data as contour plots. The configuration parameters (containing the POST key) may be overruled by the command line options, as explained below. Options -d N Differential type to be used: central difference (N=0), least squares (N=1), Richardson interpolation (N=2), circulation method (N=3) -h | --help On-line help -p | --print Print parameters, command line options and eventually used input and output filenames to stdout. The output is identic of file- name.par, in case filename is used. -g Show contour plot of the output with gnuplot. --no_g Suppresses to show contour plot of the output with gnuplot. -v | --version Print version information on standard output, then exit successfully. filename Input PIV data file. Overrides stdin and stdout. The output will be written to filename.nstr. Parameters are stored in filename.par and may be used for future use by including them in ./gpivrc. SEE ALSO
gpivtools AUTHOR
Gerber Van der Graaf 8 November 2006 GPIV_NSTRAIN(1)
All times are GMT -4. The time now is 12:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy