Sponsored Content
Full Discussion: Strings to integers?
Top Forums UNIX for Dummies Questions & Answers Strings to integers? Post 302880706 by wisecracker on Sunday 22nd of December 2013 05:23:24 PM
Old 12-22-2013
This is longhand using OSX 10.7.5, default bash terminal...
Some assumptions have been made.

Code:
Last login: Sun Dec 22 22:12:49 on ttys000
AMIGA:barrywalker~> echo "junk stuff" > /tmp/x3_y0_z-1.vtk
AMIGA:barrywalker~> echo "junk stuff" > /tmp/x6_y0_z-5.vtk
AMIGA:barrywalker~> text=$(ls /tmp/*vtk)
AMIGA:barrywalker~> echo "$text"
/tmp/x3_y0_z-1.vtk
/tmp/x6_y0_z-5.vtk
AMIGA:barrywalker~> ifs_str="$IFS"
AMIGA:barrywalker~> IFS="$IFS/_."
AMIGA:barrywalker~> array=($text)
AMIGA:barrywalker~> x1="${array[2]:1:2}"
AMIGA:barrywalker~> y1="${array[3]:1:2}"
AMIGA:barrywalker~> z1="${array[4]:1:2}"
AMIGA:barrywalker~> echo "x=$x1, y=$y1, z=$z1"
x=3, y=0, z=-1
AMIGA:barrywalker~> x2="${array[7]:1:2}"
AMIGA:barrywalker~> y2="${array[8]:1:2}"
AMIGA:barrywalker~> z2="${array[9]:1:2}"
AMIGA:barrywalker~> echo "x=$x2, y=$y2, z=$z2"
x=6, y=0, z=-5
AMIGA:barrywalker~> IFS="$ifs_str"
AMIGA:barrywalker~> _

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

integers in the if statement

hi, im trying to compare two variables in csh to put in an if statement, eg: set a = $firstnum set b = $secondnum if ($a -ge $b) echo $a But I get an error ("if: Expression syntax"). How can I make csh see my variables as integers? thanks in advance! (5 Replies)
Discussion started by: Deanne
5 Replies

2. Programming

Using write() with integers in C

I'm trying to write an integer to a file using the write() function, but write() requires the parameter to be written to be a const void*. How would I go about doing this? also: using itoa() produces a " warning: implicit declaration of function 'itoa' " even though i have #included stdlib.h (2 Replies)
Discussion started by: h@run
2 Replies

3. Shell Programming and Scripting

Add non-integers using ksh

I would like to add 4.7 and 1.2. However I am unable to do this with expr. Any simple ideas (even using something other than expr)? Example: me> expr 4 + 1 5 me> expr 4.7 + 1.2 expr: 0402-046 A specified operator requires numeric parameters. (18 Replies)
Discussion started by: 2dumb
18 Replies

4. Shell Programming and Scripting

Strings to integers in an arithmetic loop

Hi all, Could someone please advise what is the correct syntax for my little script to process a table of values? The table is as follows: 0.002432 20.827656 0.006432 23.120364 0.010432 25.914184 0.014432 20.442655 0.018432 20.015243 0.022432 21.579517 0.026432 18.886874... (9 Replies)
Discussion started by: euval
9 Replies

5. Shell Programming and Scripting

Cancel down 2 integers

Wonderful evening to all of you! My problem has to possible starting points. Well, not really, but getting to either one is no problem at all. So i got either a string in the format of "1920x1080" or simply the integers X = 1920 and Y = 1080. When I am done, I would like to have an output... (5 Replies)
Discussion started by: jakunar
5 Replies

6. Shell Programming and Scripting

Comparison treating strings as zero integers

I'm trying to write a bash script to perform basic arithmetic operations but I want to run a comparison on the arguments first to check that they're a number greater than zero. I want an error to pop up if the arguments args aren't >= 0 so I have: if ! ]; then echo "bad number: $1" fi ... (14 Replies)
Discussion started by: TierAngst
14 Replies

7. Shell Programming and Scripting

Grep float/integers but skip some integers

Hi, I am working in bash in Mac OSX, I have following 'input.txt' file: <INFO> HypoTestTool: >>> Done running HypoTestInverter on the workspace combined <INFO> HypoTestTool: The computed upper limit is: 11 +/- 1.02651 <INFO> HypoTestTool: expected limit (median) 11 <INFO> HypoTestTool: ... (13 Replies)
Discussion started by: Asif Siddique
13 Replies

8. Shell Programming and Scripting

awk -- telling the difference between strings and integers

This should be a really easy question. My input file will have a few fields that are strings in the first line, which I will extract and save as variables. The rest of the fields on every line will be integers and floating point numbers. Can awk tell the difference somehow? That is, is there... (5 Replies)
Discussion started by: Parrakarry
5 Replies

9. Shell Programming and Scripting

Bash Integers/String

Hy friends, I am newbie to bash scripting, can anyone explain how b=${a/23/BB} # Substitute "BB" for "23". this line converts "b" into string and and "d" into Integer. Thanks in advance (4 Replies)
Discussion started by: Qazi
4 Replies

10. Shell Programming and Scripting

Comparing Integers (I think)

Hi, I can't figure out what I'm missing. I'm running a query to see if there are any streams recording on my DVR before starting a scripted update. I'm guessing that it is viewing $VIDEO as a string instead of an int. I've tried everything I saw on google but it still comes back as $VIDEO is... (8 Replies)
Discussion started by: Rhysers
8 Replies
raster3dintro(1grass)						Grass User's Manual					     raster3dintro(1grass)

3D Raster data (voxel) in GRASS GIS
   3D Raster (voxel) import
       The  module  r3.in.ascii  supports  generic  x,y,z  import.  Alternatively, voxels can be generated from 3D point vector data (v.to.rast3).
       Always the full map is imported.  Volumes can also be created based on 2D elevation map(s) and value raster map(s) (r.to.rast3elev). Alter-
       natively, a volume can be composed of several 2D raster map slices which are merged into one 3D raster volume map (r.to.rast3).

   Voxel region settings and 3D MASK
       GRASS  3D  raster  map processing is always performed in the current 3D region settings (see g.region, -p3 flags), i.e.	the current region
       extent, vertical extent and current 3D resolution are used.  If the 3D resolution differs from that of the input raster map(s),	on-the-fly
       resampling  is  performed (nearest neighbor resampling).  If this is not desired, the input map(s) has/have to be reinterpolated beforehand
       with one of the dedicated modules.  Masks can be set (r3.mask).

   Voxel operations
       Powerful 3D map algebra is implemented in r3.mapcalc.

   Voxel conversion to vector or 2D raster maps
       3D vector point data can be converted to a GRASS 3D raster map (v.to.rast3).  Layers from a 3D raster map can be converted to a	2D  raster
       map (r3.to.rast).  Cross sectional 2D raster map can be extracted from 3D raster map based on a 2D elevation map (r3.cross.rast).

   Voxel statistics
       Volume statistics can be calculated with r3.stats and r3.univar.

   Voxel interpolation
       From 3D vector points, GRASS 3D raster maps can be interpolated (v.vol.rst). Results are volumes, or 2D raster maps can be also extracted.

   Voxel export
       GRASS 3D raster maps can be exported to VTK (r3.out.vtk).  VTK files can be visualized with the VTK Toolkit, Paraview and MayaVi.  GRASS 2D
       raster maps can be exported to VTK with r.out.vtk, GRASS vector maps can be exported to VTK with v.out.vtk.

       Alternatively, GRASS 3D raster maps can be imported and exported from/to Vis5D (r3.out.v5d).  Note that Vis5D is limited in the	number	of
       supported voxels.

       Finally, export to 3D ASCII is also available (r3.out.ascii).

   See also
       Introduction to GRASS raster map processing

       full index

       (C) 2008-2011 GRASS Development Team

GRASS 6.4.2														     raster3dintro(1grass)
All times are GMT -4. The time now is 09:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy