The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
grep a word from a specific line blurboy Shell Programming and Scripting 3 01-23-2008 04:13 AM
grep a word from a line Orbix UNIX for Dummies Questions & Answers 2 12-23-2007 11:52 AM
how to move word by word on command line pbsrinivas UNIX for Dummies Questions & Answers 1 11-23-2007 06:17 AM
print a line containing word in a column using grep useless79 Shell Programming and Scripting 2 11-23-2007 04:32 AM
Can a shell script pull the first word (or nth word) off each line of a text file? tricky Shell Programming and Scripting 5 08-17-2006 07:29 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-26-2008
victorbrca's Avatar
victorbrca victorbrca is offline
Registered User
  
 

Join Date: Aug 2008
Location: Canada, ON
Posts: 7
grep a word instead of a line

Hi all,


I'm a noobie at shell scripting (and Linux) with no experience on programing.

I'm trying to create a script that will download my xml calendar from Google, process it in the [month, day<TAB>description] format and dump it into $HOME/.calendar/calendar.

Eg:
April 10 Event

I'm having a hard time using field delimiter on cut because the xml code changes depending on how much info I have on that calendar entry.

Here's an example of an entry in xml:

Quote:
&lt;br /&gt;Event Status: confirmed</content><link rel='alternate' type='text/html' href='http://www.google.com/calendar/event?eid=aXY2MW1vY2sxOTNiYnQ5aG5qczlxaXNscjQgdmljdG9yYnJjYUBt' title='alternate'/><link rel='self' type='application/atom+xml' href='http://www.google.com/calendar/feeds/xxxxxxxgmail.com/public/basic/iv61mock193bbt9hnjs9qislr4'/><author><name>xxxxxx xxxxxxx</name><email>xxxxxxx@gmail.com</email></author></entry><entry><id>http://www.google.com/calendar/feeds/xxxxxxxxxxxxxgmail.com/public/basic/h40hv3rhht360l0sp36ctr2ef8</id><published>2008-09-23T02:48:41.000Z</published><updated>2008-09-23T02:48:41.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2005#event'/><title type='html'>Flooring</title><summary type='html'>When: Mon Sep 29, 2008&lt;br&gt;


&lt;br&gt;Event Status: confirmed</summary><content type='html'>When: Mon Sep 29, 2008&lt;br /&gt;
This the script I came up with:


Code:
#!/bin/bash


## Reads URL
_url=$1

## Gets Title
_get1=`wget $_url -q -O - | cut -d">" -f20 | grep title | sed 's/..title//g'`

## Gets time
_get2=`wget $_url -q -O - | cut -d">" -f3 | egrep '^W' | cut -d" " -f3,4 | sed 's/,//g'`


#Counter
_cnt=`echo "$_get1" | wc -l`
_cnt=$(( _cnt + 1 ))
#echo $_cnt
e="1"



while [ "$e" -lt "$_cnt" ] ; do
        _title=`echo "$_get1" | head -n "$e" | tail -n 1`
        _time=`echo "$_get2" | head -n "$e" | tail -n 1`
#       echo -e "$_time\t$_title"
#       echo "$e"
        e=$(( e + 1 ))
done

This almost works. It ends up missing one "title" due to the delimiter changes.

Any help is more than appreciated.

Thanks!!

Vic.
  #2 (permalink)  
Old 09-26-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,556
parsing xml using shell?? I suggest you use a programming language (eg Python/Perl) that supports XML parsers.
  #3 (permalink)  
Old 09-28-2008
neked neked is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 56
agreed, download python2.5 and use xml.etree.cElementTree library to parse your XML. infinitely easier.
  #4 (permalink)  
Old 09-28-2008
victorbrca's Avatar
victorbrca victorbrca is offline
Registered User
  
 

Join Date: Aug 2008
Location: Canada, ON
Posts: 7
Quote:
Originally Posted by ghostdog74 View Post
parsing xml using shell?? I suggest you use a programming language (eg Python/Perl) that supports XML parsers.
So that's the problem. I didn't know that this was the proper way of doing it.

I guess it will take a while before I can finish the script them. I gotta learn shell before I can jump into another language.

Thanks for the reply!

Vic.
  #5 (permalink)  
Old 03-08-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,891
PS: You may not need to. Google's Calendars can be exported into the "iCal" format. Chances are, the program that looks at .calendar already honors this format.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0