|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
"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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
"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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|