PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Unix required: one line comand to date Column to a fixed length file parsing the file name
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Unix required: one line comand to date Column to a fixed length file parsing the file name

Réponse
 
LinkBack Outils de la discussion
Vieux 13/03/2007, 16h17   #1
ajay.balki
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Unix required: one line comand to date Column to a fixed length file parsing the file name

Hi ,

I have a fixed length file of records size 50 ,
file_nm.YYYYMMDD.dat .
My requirement is that : To parse the file name for date and add the
apped this date to the end of each record .

After this the resultant record size becomes 58 .

Is there one line command with AWK /SED i can make use for this
purpose .

Thanks in Advance ,
Ajay

  Réponse avec citation
Vieux 13/03/2007, 16h27   #2
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Unix required: one line comand to date Column to a fixedlength file parsing the file name

ajay.balki wrote:
> Hi ,
>
> I have a fixed length file of records size 50 ,
> file_nm.YYYYMMDD.dat .
> My requirement is that : To parse the file name for date and add the
> apped this date to the end of each record .
>
> After this the resultant record size becomes 58 .
>
> Is there one line command with AWK /SED i can make use for this
> purpose .
>
> Thanks in Advance ,
> Ajay
>


awk -F. '{print $0 $(NF-1)}' file

Ed.
  Réponse avec citation
Vieux 13/03/2007, 17h03   #3
ajay.balki
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Unix required: one line comand to date Column to a fixed length file parsing the file name

On Mar 13, 10:27 am, Ed Morton <mor...@lsupcaemnt.com> wrote:
> ajay.balki wrote:
> > Hi ,

>
> > I have a fixed length file of records size 50 ,
> > file_nm.YYYYMMDD.dat .
> > My requirement is that : To parse the file name for date and add the
> > apped this date to the end of each record .

>
> > After this the resultant record size becomes 58 .

>
> > Is there one line command with AWK /SED i can make use for this
> > purpose .

>
> > Thanks in Advance ,
> > Ajay

>
> awk -F. '{print $0 $(NF-1)}' file
>
> Ed.- Hide quoted text -
>
> - Show quoted text -


Thanks Ed ,

But what I wanted is :

my file name is : test_file.d.20070301.dat

$ cat test_file.d.20070301.dat
This is Test File Rec1
This is Test File Rec2


I wanted a command on using it will transform my file records to :

$ cat test_file.d.20070301.dat
This is Test File Rec120070301
This is Test File Rec220070301

Thanks In Advance



  Réponse avec citation
Vieux 13/03/2007, 17h19   #4
Radoulov, Dimitre
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Unix required: one line comand to date Column to a fixed length file parsing the file name


"ajay.balki" wrote in message ...
[...]
> my file name is : test_file.d.20070301.dat
>
> $ cat test_file.d.20070301.dat
> This is Test File Rec1
> This is Test File Rec2
>
> I wanted a command on using it will transform my file records to :
>
> $ cat test_file.d.20070301.dat
> This is Test File Rec120070301
> This is Test File Rec220070301


awk '{print $0 substr(FILENAME,length(FILENAME)-11,8)}' infile[s]



Dimitre


  Réponse avec citation
Vieux 13/03/2007, 17h27   #5
Radoulov, Dimitre
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Unix required: one line comand to date Column to a fixed length file parsing the file name


"Radoulov, Dimitre" wrote in message ...
>
> "ajay.balki" wrote in message ...
> [...]
>> my file name is : test_file.d.20070301.dat
>>
>> $ cat test_file.d.20070301.dat
>> This is Test File Rec1
>> This is Test File Rec2
>>
>> I wanted a command on using it will transform my file records to :
>>
>> $ cat test_file.d.20070301.dat
>> This is Test File Rec120070301
>> This is Test File Rec220070301

>
> awk '{print $0 substr(FILENAME,length(FILENAME)-11,8)}' infile[s]


This has to be more efficient (I suppose):

awk 'FNR==1{dt=substr(FILENAME,length(FILENAME)-11,8)}
{print $0 dt}' infile[s]


Dimitre




  Réponse avec citation
Vieux 14/03/2007, 00h04   #6
John W. Krahn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Unix required: one line comand to date Column to a fixedlength file parsing the file name

ajay.balki wrote:
>
> But what I wanted is :
>
> my file name is : test_file.d.20070301.dat
>
> $ cat test_file.d.20070301.dat
> This is Test File Rec1
> This is Test File Rec2
>
>
> I wanted a command on using it will transform my file records to :
>
> $ cat test_file.d.20070301.dat
> This is Test File Rec120070301
> This is Test File Rec220070301


perl -i -lpe'$ARGV =~ /\b(\d{8})\b/ and $_ .= $1' test_file.d.20070301.dat



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h52.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12682 seconds with 14 queries