Sponsored Content
Top Forums Shell Programming and Scripting perl instead of grep 'conversion' help? Post 302452682 by Habitual on Sunday 12th of September 2010 04:50:44 PM
Old 09-12-2010
perl instead of grep 'conversion' help?

Hello:

I butchered a shell script together, but my script kung-fu is 5 years old and all I've used for 5 years are for i loops. I hope that some perl guru can do in 5 minutes what takes me 5 weeks, so I am asking for help.

I have a simple script using "grep -A 2 'string' /path/to/file" but after importing my data into it (if's a FF plugin called ReminderFox), the rows are "re-ordered"

script now outputs: (source ics file is 'US Holidays')
  1. SUMMARY:Washington's Birthday
    DTSTART;VALUE=DATE:20090216
    DTEND;VALUE=DATE:20090217

But grep'ing with the same command on my backup file, I get this kind of output:
  1. SUMMARY:Technical Support Specialist
    UID:1281092384117-979283602
    DTSTART:20100812T085900''

In simplest terms, my request is...
I'd like to have these fields from any ics file that has them:
SUMMARY:
DTSTART;VALUE=DATE:
DTEND;VALUE=DATE:
(and echo a newline)

and if possible convert DTSTART|DTEND data...
from it's current format of "+%Y%m%d" to "+%h %m %Y"

This is NOT homework.
Bash = GNU bash, version 4.0.38 | Awk = GNU Awk 3.1.7
Grep = GNU grep 2.6.3 | perl = 5.10.0

I hope this is clear. Smilie
Thank you for your time.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Another bash shell to perl conversion

Hello everyone. I am new to linux and need help again. I need help converting this bash shell to linux: for i in `ls -l *.txt` do `./cnvidtf.pl $i` `curl -u login:pswd --disable-espv -T loadfile.seq ftp://11.1.11.1` `mysql -u login -h 11.1.11.1 -ppswd < lddocs.sql` done Thanks! Any help... (6 Replies)
Discussion started by: freak
6 Replies

2. Shell Programming and Scripting

Perl in KSH - julian conversion

Hello Everyone, I have this code misbehaving in one of my scripts, I have a var containing the sequential number of the day for the year and I am suppose to get the regular date for that day and its weekday. If I set the day to 273 I get back 2008/09/31 which is not a proper date. can you help... (7 Replies)
Discussion started by: gio001
7 Replies

3. Shell Programming and Scripting

[Perl] Timestamp conversion

Hi, I have searched, read and tried, but no luck. I have this code: #!/bin/perl -w #-d use strict; use POSIX qw(strftime); my $getprpw_list="/usr/lbin/getprpw -l"; my $host = "nbsol151"; my $user = "genadmin"; my %uid; my %spwchg; my %upwchg; my %slogint; (2 Replies)
Discussion started by: ejdv
2 Replies

4. Shell Programming and Scripting

Encoding conversion in PERL script

I have oracle 9i database installed with UTF-8 Encoding. I want a perl script that converts unicode to utf8 before commiting in database and utf8 to unicode when retreiving from database For example : the word Ïntêrnatïônàlîzâtion has to be stored in database as Internationalization and when retreived... (6 Replies)
Discussion started by: vkca
6 Replies

5. Shell Programming and Scripting

Perl Conversion Tool

I want a perl script that converts special characters (French, German, Italy, Denmark character set) into database compatible format and retrieves the back in the original format. A generic functionality will be developed which converts any special characters (having > 8 bit format). I tried... (3 Replies)
Discussion started by: perl2ask
3 Replies

6. Shell Programming and Scripting

Conversion from Perl to Shell scripting

Hai ! I am doing a research on Bioinformatics and a part of the code in perl have to be converted to shell scripting. I am new to shell programming. Pls. kindly help me to convert this code to shell script though it is somewhat lengthy. PLS KINDLY HELP ME. THANKS IN ADVANCE. my @FreeEnergy =... (1 Reply)
Discussion started by: kswapnadevi
1 Replies

7. Shell Programming and Scripting

Timestamp conversion in PERL

Hi, I have a file as below I need to overwrite the 2 nd column alone to numeric format like "06122011030414012345" as per the timestamp value output file should be the microseconds can be neglected if required. Any help will be appreciated. Thanks in advance (1 Reply)
Discussion started by: irudayaraj
1 Replies

8. Shell Programming and Scripting

conversion of code in perl and python

How to convert below bash code in perl and python. for BLOCK in /sys/block/emcpow* do echo "100000" > "$BLOCK"/queue/nr_requests echo "noop" > "$BLOCK"/queue/scheduler done (2 Replies)
Discussion started by: learnbash
2 Replies

9. Shell Programming and Scripting

conversion of loop in perl

Hello Sir, How can i convert below two loop lines in perl for BLOCK in /sys/block/myblock* for BLOCK in /dev/myblock* How i can write them in perl like foreach( </sys/block/myblock*/queue/nr_requests> ) (5 Replies)
Discussion started by: learnbash
5 Replies

10. Shell Programming and Scripting

Perl - TimeDate format conversion

Dear All, I need to print the below value from excel column 20160219T05:21:59+0100 to 19-FEB-2016 05:21:11 Can anyone help on this datetime format conversion. Please suggest in print logic itself. Regards, Kumaresan P (6 Replies)
Discussion started by: Kumaresanpvk
6 Replies
DateTime::Format::ICal(3pm)				User Contributed Perl Documentation			       DateTime::Format::ICal(3pm)

NAME
DateTime::Format::ICal - Parse and format iCal datetime and duration strings SYNOPSIS
use DateTime::Format::ICal; my $dt = DateTime::Format::ICal->parse_datetime( '20030117T032900Z' ); my $dur = DateTime::Format::ICal->parse_duration( '+P3WT4H55S' ); # 20030117T032900Z DateTime::Format::ICal->format_datetime($dt); # +P3WT4H55S DateTime::Format::ICal->format_duration($dur); DESCRIPTION
This module understands the ICal date/time and duration formats, as defined in RFC 2445. It can be used to parse these formats in order to create the appropriate objects. METHODS
This class offers the following methods. o parse_datetime($string) Given an iCal datetime string, this method will return a new "DateTime" object. If given an improperly formatted string, this method may die. o parse_duration($string) Given an iCal duration string, this method will return a new "DateTime::Duration" object. If given an improperly formatted string, this method may die. o parse_period($string) Given an iCal period string, this method will return a new "DateTime::Span" object. If given an improperly formatted string, this method may die. o parse_recurrence( recurrence => $string, ... ) Given an iCal recurrence description, this method uses "DateTime::Event::ICal" to create a "DateTime::Set" object representing that recurrence. Any parameters given to this method beside "recurrence" will be passed directly to the "DateTime::Event::ICal->recur" method. If given an improperly formatted string, this method may die. This method accepts optional parameters "dtstart" and "dtend". These parameters must be "DateTime" objects. The iCal spec requires that "dtstart" always be included in the recurrence set, unless this is an "exrule" statement. Since we don't know what kind of statement is being parsed, we do not include "dtstart" in the recurrence set. o format_datetime($datetime) Given a "DateTime" object, this methods returns an iCal datetime string. The iCal spec requires that datetimes be formatted either as floating times (no time zone), UTC (with a 'Z' suffix) or with a time zone id at the beginning ('TZID=America/Chicago;...'). If this method is asked to format a "DateTime" object that has an offset-only time zone, then the object will be converted to the UTC time zone internally before formatting. For example, this code: my $dt = DateTime->new( year => 1900, hour => 15, time_zone => '-0100' ); print $ical->format_datetime($dt); will print the string "19000101T160000Z". o format_duration($duration) Given a "DateTime::Duration" object, this methods returns an iCal duration string. The iCal standard does not allow for months or years in a duration, so if a duration for which "delta_months()" is not zero is given, then this method will die. o format_period($span) Given a "DateTime::Span" object, this methods returns an iCal period string, using the format "DateTime/DateTime". o format_period_with_duration($span) Given a "DateTime::Span" object, this methods returns an iCal period string, using the format "DateTime/Duration". o format_recurrence($arg [,$arg...] ) This method returns a list of strings containing ICal statements. In scalar context it returns a single string which may contain embedded newlines. The argument can be a "DateTime" list, a "DateTime::Span" list, a "DateTime::Set", or a "DateTime::SpanSet". ICal "DATE" values are not supported. Whenever a date value is found, a "DATE-TIME" is generated. If a recurrence has an associated "DTSTART" or "DTEND", those values must be formatted using "format_datetime()". The "format_recurrence()" method will not do this for you. If a "union" or "complement" of recurrences is being formatted, they are assumed to have the same "DTSTART" value. Only "union" and "complement" operations are supported for recurrences. This is a limitation of the ICal specification. If given a set it cannot format, this method may die. Only "DateTime::Set::ICal" objects are formattable. A set may change class after some set operations: $recurrence = $recurrence->union( $dt_set ); # Ok - $recurrence still is a DT::Set::ICal $recurrence = $dt_set->union( $recurrence ); # Not Ok! - $recurrence is a DT::Set now The only unbounded recurrences currently supported are the ones generated by the "DateTime::Event::ICal" module. You can add ICal formatting support to a custom recurrence by using the "DateTime::Set::ICal" module: $custom_recurrence = DateTime::Set::ICal->from_recurrence ( recurrence => sub { $_[0]->truncate( to => 'month' )->add( months => 1 ) } ); $custom_recurrence->set_ical( include => [ 'FREQ=MONTHLY' ] ); SUPPORT
Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. AUTHORS
Dave Rolsky <autarch@urth.org> and Flavio Soibelmann Glock <fglock@pucrs.br> Some of the code in this module comes from Rich Bowen's "Date::ICal" module. COPYRIGHT
Copyright (c) 2003 David Rolsky. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. SEE ALSO
datetime@perl.org mailing list http://datetime.perl.org/ perl v5.10.0 2009-05-24 DateTime::Format::ICal(3pm)
All times are GMT -4. The time now is 07:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy