DaemonForums  

Go Back   DaemonForums > FreeBSD > FreeBSD General

FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 26th May 2008
piercedfreak piercedfreak is offline
New User
 
Join Date: May 2008
Posts: 2
Thanked 0 Times in 0 Posts
Default sed help

i have a small weather script, for graphing weather, but sed doesnt work right for part of it, and i do not see anything wrong with it. it has been bugging me for about 2 days now, so i figure its time to post, and ask.

Code:
cat /var/tmp/localweather.xml | grep "<s>" | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' | sed 's/C|c|L|l|M|m|N|n|A|a\//0/g'
basically if the weather report says the wind is "calm" or "N\A" of any sort, its supposed to change it to 0. but it doesnt, it still reports "calm".
Reply With Quote
  #2   (View Single Post)  
Old 26th May 2008
ephemera's Avatar
ephemera ephemera is offline
Knuth's homeboy
 
Join Date: Apr 2008
Posts: 537
Thanked 49 Times in 43 Posts
Default

sed -E 's/([Cc][Aa][Ll][Mm]|[Nn][/\][Aa])/0/g'
Reply With Quote
  #3   (View Single Post)  
Old 26th May 2008
harisman's Avatar
harisman harisman is offline
Fdisk Soldier
 
Join Date: May 2008
Location: Hellas (Greece)
Posts: 66
Thanked 5 Times in 4 Posts
Default

This is my approach, being an awk zealot

Code:
awk '/<s>/ {gsub(/<s>|<\/s>/,"",$1); gsub(/[^0-9]+/,"0",$1);print}' /var/tmp/localweather.xml
Reply With Quote
  #4   (View Single Post)  
Old 26th May 2008
piercedfreak piercedfreak is offline
New User
 
Join Date: May 2008
Posts: 2
Thanked 0 Times in 0 Posts
Default

wow, i must learn awk better then...

thanks for the help, ill give it a shot soon as i get home...
Reply With Quote
  #5   (View Single Post)  
Old 28th May 2008
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Thanked 112 Times in 104 Posts
Default

AWK is worth learning.

Although one could probably settle on Perl instead of sed+awk, it's best to know all three or at least sed & awk ;-)
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
  #6   (View Single Post)  
Old 28th May 2008
scottro's Avatar
scottro scottro is offline
Real Name: Scott Robbins
Spam Deminer
 
Join Date: Apr 2008
Location: NYC
Posts: 291
Thanked 31 Times in 25 Posts
Default

I like awk. I'm not at all good at it, but I find where many of the real aces would use perl, I can get by with awk. (plus sed.)
Reply With Quote
  #7   (View Single Post)  
Old 28th May 2008
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Thanked 112 Times in 104 Posts
Default

I find Perl best suited when it is inconvenient to be limited to POSIX sed and old awk.
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
  #8   (View Single Post)  
Old 28th May 2008
lvlamb's Avatar
lvlamb lvlamb is offline
Real Name: Louis V. Lambrecht
Spam Deminer
 
Join Date: May 2008
Location: .be
Posts: 221
Thanked 25 Times in 24 Posts
Default

I would use perl to publish a portable app. But my apps always are pre-alpha
Sometimes use awk, but can't get rid of exit codes (breaking a line with a success). Mostly use it to re-order(print) data output.
For what the shell can't do, am on sed, trying to get rid of gsed in my code. Still using gtr though.
Found that gdate handles most of my datestrings properly, never read date::manip.
Definitively put bash out of bonds, {pd}ksh is much cleaner and available on other OSes.

Fwiw,
one-liner to get rid of xml/html tabs, deletes anything between < and the next >
Code:
s/<[^>]*>//g
(there are many packages in the tree to de-htmlize)
__________________
da more I know I know I know nuttin'
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:39 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick