grep a word instead of a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep a word instead of a line
# 1  
Old 09-26-2008
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!! Smilie

Vic.
# 2  
Old 09-26-2008
parsing xml using shell?? I suggest you use a programming language (eg Python/Perl) that supports XML parsers.
# 3  
Old 09-28-2008
agreed, download python2.5 and use xml.etree.cElementTree library to parse your XML. infinitely easier.
# 4  
Old 09-28-2008
Quote:
Originally Posted by ghostdog74
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! Smilie

Vic.
# 5  
Old 03-08-2009
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Write a script for getout afew line and grep a define word

dear all Hi i want write a script can count number of my log file and every 5min run script for cgk log file for find a specific word such as Error for example in first 5 min we have 500 line in my log file and in second 5min we have 2500 line in my log file how can chk error word in my log... (4 Replies)
Discussion started by: Baber
4 Replies

2. Shell Programming and Scripting

How to grep nth word in line?

my input file content is like this GEFITINIB 403 14 -4.786873 -4.786873 -1.990111 0.000000 0.000000 -1.146266 -39.955912 483 VANDETANIB 404 21 -4.754243 -4.754243 -2.554131 -0.090303 0.000000 -0.244210 -41.615502 193 VANDETANIB 405 21 -4.737541 -4.737541 -2.670195 -0.006006 0.000000 -0.285579... (4 Replies)
Discussion started by: chandu87
4 Replies

3. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

4. Shell Programming and Scripting

Grep to isolate a text file line and Awk to select a word?

I am looking at using grep to locate the line in the text file and them use awk to select a word or words out of it. I know awk needs -v to allow a variable to be used, but also needs -F to allow the break up of the sentence and allow the location of separate variables. $line = grep "1:" File |... (8 Replies)
Discussion started by: Ironguru
8 Replies

5. Shell Programming and Scripting

Command to grep a word and print the whole line splitted into many

Hi, I need to search a word in the java file. Assume the line in the java file is, (the line was splitted into 3 lines) 1.operationContext.sendFeedback(2.FeedbackType.ERROR, null, "Input is empty.", "Input Details: pr 3.ovide Valid pair(s): "+pairType); When i grep for the word... (6 Replies)
Discussion started by: tulasiram
6 Replies

6. UNIX for Dummies Questions & Answers

Can grep command return word instead of complete line

Hi Is there any way GREP command can return word and not complete line. My file has following data: Hello Everyone I am NitinrajSrivastava Hi Friends Welcome VrajSrivastava I am using grep 'raj' which is returning me complete line.However I want only the word having keyword 'raj'. Required... (11 Replies)
Discussion started by: dashing201
11 Replies

7. UNIX for Dummies Questions & Answers

How to grep word + next line in solaris 10?

Hi my unix friends, How do I grep a word and next line with solaris 10. tnx Mehrdad ---------- Post updated at 03:17 PM ---------- Previous update was at 03:09 PM ---------- I found this one: cat <file_name> | awk '/<seek_word>/ {print;getline;print}' (3 Replies)
Discussion started by: mehrdad68
3 Replies

8. Shell Programming and Scripting

grep a word from a specific line

for example: searches only for single word for single word this is line three match=$(grep -n -e "single" data.txt) this command will stored "..... single ...... single" into search. how can i grep the single word just from line 2 only?? (3 Replies)
Discussion started by: blurboy
3 Replies

9. UNIX for Dummies Questions & Answers

grep a word from a line

Hi there, Is there a way to grep a word from a line and display only the words beginning from the search word? Say I have a file named file.txt that contains below: I am a file Hello there Reader Orbix I hope you feel good today What I want is to grep the word "there": $ grep "there"... (2 Replies)
Discussion started by: Orbix
2 Replies

10. Shell Programming and Scripting

print a line containing word in a column using grep

hi, how to print a row which contains a perticular word in its third column using grep, cut, or any thing else. thanks (2 Replies)
Discussion started by: useless79
2 Replies
Login or Register to Ask a Question