![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Parsing file, yaml file? Extracting specific sections | Rhije | Shell Programming and Scripting | 3 | 01-22-2009 06:36 PM |
| Extracting information from Config files /text processing | oconmx | Shell Programming and Scripting | 3 | 01-21-2009 07:09 PM |
| Extracting data from text file based on configuration set in config file | suparnbector | Shell Programming and Scripting | 3 | 08-10-2007 03:25 AM |
| Have a shell script check for a file to exist before processing another file | heprox | Shell Programming and Scripting | 3 | 11-14-2006 03:26 AM |
| [Splitting file] Extracting group of segments from one file to others | ozgurgul | Shell Programming and Scripting | 1 | 09-14-2006 01:17 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Extracting From A File Then Processing
Hi. Im working with this data in a file:
Code:
-94.49109387652327,39.2956736296775 -93.0906917141962,38.72762798197614 -90.57659976220785,-40.25685140137304 -92.340961875134,39.44522321129584 92.340961875134,39.44522321129584 -94.72083812873272,37.63567097374739 All that data was extracted from a KML using: Code:
sed -n 's/.*<coordinates>\(.*\)\,.*/\1/ip;T' Test.kml Code:
<coordinates>-90.57659976220785,40.25685140137304,0</coordinates> |
|
||||
|
Hi.
You could try something like: Code:
sed -n 's/.*<coordinates>\(.*\)\,.*/\1/ip;T' Test.kml | while IFS=, read A B; do echo a is $A b is $B ... done i.e. Code:
-94.49109387652327,39.2956736296775 -93.0906917141962,38.72762798197614 -90.57659976220785,-40.25685140137304 -92.340961875134,39.44522321129584 92.340961875134,39.44522321129584 -94.72083812873272,37.63567097374739 Code:
a is -94.49109387652327 b is 39.2956736296775 a is -93.0906917141962 b is 38.72762798197614 a is -90.57659976220785 b is -40.25685140137304 a is -92.340961875134 b is 39.44522321129584 a is 92.340961875134 b is 39.44522321129584 a is -94.72083812873272 b is 37.63567097374739 |
|
||||
|
This is just to compile some stuff for my reference.
Code:
sed -n 's/.*<coordinates>\(.*\)\,.*/\1/ip;T' Test.kml -94.49109387652327,39.2956736296775 -93.0906917141962,38.72762798197614 -90.57659976220785,40.25685140137304 -92.340961875134,39.44522321129584 -92.340961875134,39.44522321129584 -94.72083812873272,37.63567097374739 sed -n 's/.*<longitude>\(.*\)<\/longitude>.*/\1/ip;T' Test.kml -94.49109387652327 -93.0906917141962 -90.57659976220786 -92.340961875134 -92.340961875134 -94.72083812873272 #Math with decimals a=`echo "1+1.2" | bc` && echo $a 2.2 a=`dc -e '1.2 1+p'` echo $a 2.2 #Extracting coords as vars then processing sed -n 's/.*<coordinates>\(.*\)\,.*/\1/ip;T' Test.kml | while IFS=, read A B; do echo a is $A b is $B echo "asdf" done a is -94.49109387652327 b is 39.2956736296775 a is -93.0906917141962 b is 38.72762798197614 a is -90.57659976220785 b is 40.25685140137304 #Multi Condition if statement if [ $i = "+" -o $i = "-" -o $i = "/" -o $i = "%" ]; then $x=$vr1 else print "You have entered an invalid option." |
|
||||
|
Quote:
Have a word with Neo. He might want to endorse it! |
|
||||
|
Hah yea it just made sense. Easiest way to transport code from home to work. I tried out
Code:
sed -n 's/.*<coordinates>\(.*\)\,.*/\1/ip;T' Test.kml | while IFS=, read A B; do echo a is $A b is $B echo "asdf" done |
|
||||
|
Hi.
Well, the nawk from vger works fine, which would leave you with: Code:
nawk -F'[>,]' '{print $2, $3}' | while read A B; do
echo a is $A b is $B
done
Or an alternative sed: Code:
sed 's/.*<coordinates>\(.*\)<.*/\1/' | while IFS=, read A B junk; do echo a is $A b is $B done |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|