Sponsored Content
Top Forums Shell Programming and Scripting PERL String to Date (Custom format yyyymmdd to dd-mon-yyyy) Post 302401172 by vivekraj on Friday 5th of March 2010 05:17:17 AM
Old 03-05-2010
We can easily do that by using regular expression in Perl.

Code:
$line="20091029 Text File";
$line=~/([0-9]{4})([0-9]{2})([0-9]{2}).*/;
print "$3-$2-$1";

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to convert the string YYYYMMDD into YYYY.MM.DD

how to convert the string YYYYMMDD into YYYY.MM.DD Please advice (1 Reply)
Discussion started by: spatra
1 Replies

2. UNIX for Dummies Questions & Answers

Format date from MM/DD/YYYY to YYYYMMDD

I have a file with some date columns in MM/DD/YYYY format: SMPBR|DUP-DO NOT USE|NEW YORK||16105|BA5270715|6/6/2007 |MWERNER|109||||JOHN||SMITH|MD|72211118||||||74559|21 WILMINGTON RD||D|11/6/2003|SL# MD CONTACT-LIZ RICHARDS|||0|Y|N||1411458| And I want to convert the date format to: ... (5 Replies)
Discussion started by: ChicagoBlues
5 Replies

3. Shell Programming and Scripting

convert date format YYYYMMDD to MM/DD/YYYY

In my shell script i have a variable which stores date in the format of YYYYMMDD. Is there any way to format this value to MM/DD/YYYY. Thanks. (8 Replies)
Discussion started by: nasirgondal
8 Replies

4. Shell Programming and Scripting

Converting date DD MM YYYY to DD MON YYYY

Hello, I am writing a script that parses different logs and produces one. In the source files, the date is in DD MM YYYY HH24:MI:SS format. In the output, it should be in DD MON YYY HH24:MI:SS (ie 25 Jan 2010 16:10:10) To extract the dates, I am using shell substrings, i.e.: read line ... (4 Replies)
Discussion started by: Adamm
4 Replies

5. Shell Programming and Scripting

Converting Date from YYYYMMDD to DD-MON-YYYY

Hi , I need to convert date from YYYYMMDD to DD-MON-YYYY e.g 20111214 to 14-Dec-2011 Please help. (17 Replies)
Discussion started by: ady_koolz
17 Replies

6. Shell Programming and Scripting

Validating date in yyyymmdd format using PERL

Hi all, i had a code where in user will enter a date in yyyymmdd format.. i didnt use any validation for the date and now the problem is if a user enters date instead of month after year it is proceeding with the code.. like if the date is 20120426 and if the user enters 20122604 it... (4 Replies)
Discussion started by: smarty86
4 Replies

7. Shell Programming and Scripting

Date conversion help from dd/mm/yyyy to dd/Mon/yyyy i.e. 28/10/2012 to 28/Oct/2012

Hi I have a problem with Date format in my code. 1st I am trying to convert today's date to yesterday's using YESTERDAY3=`perl -e '@y=localtime(time()-86400); printf "%04d/%02d/%02d",$y+1900,$y+1,$y;$y;'` And once it is done I am trying to using the yesterday date in a grep command to... (3 Replies)
Discussion started by: nithinankam
3 Replies

8. Programming

Date format change from mm/dd/yyyy to yyyymmdd in comma seperate line in perl

Hi All, I have line ,A,FDRM0002,12/21/2017,,0.961751583,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, it contains date in mm/dd/yyyy format i want to change this to yyyymmdd format using perl. Use code tags, thanks. (8 Replies)
Discussion started by: vishal0746
8 Replies

9. Shell Programming and Scripting

Convert string (YYYYMMDD) format to date in Sun OS

Hi All I need help in converting a string of YYYYMMDD format to date in Sun OS and then find out if the day is a Wednesday or not. The "date -d" option is not working and your help is much appreciated. The date command usage from the operating system we use here is as follows: usage: ... (1 Reply)
Discussion started by: SK123
1 Replies

10. Solaris

Convert string (YYYYMMDD) format to date in Sun OS

Hi All I need help in converting a string of YYYYMMDD format to date in Sun OS and then find out if the day is a Wednesday or not. The "date -d" option is not working and your help is much appreciated. The date command usage from the operating system we use here is as follows: Thanks, SK (11 Replies)
Discussion started by: SK123
11 Replies
Text::MicroTemplate(3pm)				User Contributed Perl Documentation				  Text::MicroTemplate(3pm)

NAME
Text::MicroTemplate - Micro template engine with Perl5 language SYNOPSIS
use Text::MicroTemplate qw(:all); # compile template, and render $renderer = build_mt('hello, <?= $_[0] ?>'); $html = $renderer->('John')->as_string; # or in one line $html = render_mt('hello, <?= $_[0] ?>', 'John')->as_string; # complex form $mt = Text::MicroTemplate->new( template => 'hello, <?= $query->param('user') ?>', ); $code = $mt->code; $renderer = eval << "..." or die $@; sub { my $query = shift; $code->(); } ... $html = $renderer->(CGI->new)->as_string; DESCRIPTION
Text::MicroTemplate is a standalone, fast, intelligent, extensible template engine with following features. standalone Text::MicroTemplate does not rely on other CPAN modules. fast Based on Mojo::Template, expressions in the template is perl code. intelligent Text::MicroTemplate automatically escapes variables when and only when necessary. extensible Text::MicroTemplate does not provide features like template cache or including other files by itself. However, it is easy to add you own (that suites the most to your application), by wrapping the result of the module (which is a perl expression). The module only provides basic building blocks for a template engine. Refer to Text::MicroTemplate::File for higher-level interface. TEMPLATE SYNTAX
The template language is Perl5 itself! # output the result of expression with automatic escape <?= $expr ?> (tag style) ?= $expr (per-line) # execute perl code (tag style) <? foo() ?> ? foo() # comment (tag style) <?# comment ?> ?# comment # loops <ul> ? for my $item (@list) { <li><?= $item ?></li> ? } </ul> EXPORTABLE FUNCTIONS
build_mt($template) Returns a subref that renders given template. Parameters are equivalent to Text::MicroTemplate->new. # build template renderer at startup time and use it multiple times my $renderer = build_mt('hello, <?= $_[0] ?>!'); sub run { ... my $hello = $renderer->($query->param('user')); ... } render_mt($template, @args) Utility function that combines build_mt and call to the generated template builder. # render $hello = render_mt('hello, <?= $_[0] ?>!', 'John'); # print as HTML print $hello->as_string; # use the result in another template (no double-escapes) $enc = render_mt('<h1><?= $_[0] ?></h1>', $hello); Intertally, the function is equivalent to: build_mt($template)->(@_); encoded_string($str) wraps given string to an object that will not be escaped by the template engine OO-STYLE INTERFACE Text::MicroTemplate provides OO-style interface to handle more complex cases. new($template) new(%args) new(\%args) Constructs template renderer. In the second or third form, parameters below are recognized. template template string (mandatory) escape_func escape function (defaults to Text::MicroTemplate::escape_html), no escape when set to undef package_name package under where the renderer is compiled (defaults to caller package) code() returns perl code that renders the template when evaluated filter(sub filter_func { ... })->(sub { template lines }) filters given template lines ? $_mt->filter(sub { s/Hello/Good bye/g })->(sub { Hello, John! ? }) DEBUG
The "MICRO_TEMPLATE_DEBUG" environment variable helps debugging. The value 1 extends debugging messages, 2 reports compiled Perl code with "warn()", 3 is like 2 but uses "die()". SEE ALSO
Text::MicroTemplate::File Text::MicroTemplate::Extended AUTHOR
Kazuho Oku <kazuhooku gmail.com> Tokuhiro Matsuno <tokuhirom AAJKLFJEF GMAIL COM> The module is based on Mojo::Template by Sebastian Riedel. LICENSE
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2010-09-06 Text::MicroTemplate(3pm)
All times are GMT -4. The time now is 10:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy