Need Shell Script help #2

  • Follow


Hi,
I have the following file
swadmin@tb142:/rangedoms1/working/
CRST_OVERLAY_ENHANCE_Analysis_RNGCTRL_DEV> cat exp_aovr_send_new.dat
0001349000174P00000012D-ATPNB050062184TPNB050063880
0001349000174P60000329C-ATPNB050064199TPNB050064268

Now i need the above file in the below format i.e splitting up of
range character 23 to 25 in each record.
Resulting file
____________________
0001349000174P00000012DTPNB050062184TPNB050063880
0001349000174P00000012CTPNB050062184TPNB050063880
0001349000174P00000012BTPNB050062184TPNB050063880
0001349000174P00000012ATPNB050062184TPNB050063880
0001349000174P60000329CTPNB050064199TPNB050064268
0001349000174P60000329BTPNB050064199TPNB050064268
0001349000174P60000329ATPNB050064199TPNB050064268
0
Reply injam4u (13) 7/1/2008 6:59:14 AM

injam4u@gmail.com wrote:
> Hi,
> I have the following file
> swadmin@tb142:/rangedoms1/working/
> CRST_OVERLAY_ENHANCE_Analysis_RNGCTRL_DEV> cat exp_aovr_send_new.dat
> 0001349000174P00000012D-ATPNB050062184TPNB050063880
> 0001349000174P60000329C-ATPNB050064199TPNB050064268
> 
> Now i need the above file in the below format i.e splitting up of
> range character 23 to 25 in each record.
> Resulting file
> ____________________
> 0001349000174P00000012DTPNB050062184TPNB050063880
> 0001349000174P00000012CTPNB050062184TPNB050063880
> 0001349000174P00000012BTPNB050062184TPNB050063880
> 0001349000174P00000012ATPNB050062184TPNB050063880
> 0001349000174P60000329CTPNB050064199TPNB050064268
> 0001349000174P60000329BTPNB050064199TPNB050064268
> 0001349000174P60000329ATPNB050064199TPNB050064268

Read the output of:

"man cut"

Robert
0
Reply robert.f.harris (386) 7/1/2008 8:36:04 AM


injam4u@gmail.com wrote:
> Hi,
> I have the following file
> swadmin@tb142:/rangedoms1/working/
> CRST_OVERLAY_ENHANCE_Analysis_RNGCTRL_DEV> cat exp_aovr_send_new.dat
> 0001349000174P00000012D-ATPNB050062184TPNB050063880
> 0001349000174P60000329C-ATPNB050064199TPNB050064268
> 
> Now i need the above file in the below format i.e splitting up of
> range character 23 to 25 in each record.
> Resulting file
> ____________________
> 0001349000174P00000012DTPNB050062184TPNB050063880
> 0001349000174P00000012CTPNB050062184TPNB050063880
> 0001349000174P00000012BTPNB050062184TPNB050063880
> 0001349000174P00000012ATPNB050062184TPNB050063880
> 0001349000174P60000329CTPNB050064199TPNB050064268
> 0001349000174P60000329BTPNB050064199TPNB050064268
> 0001349000174P60000329ATPNB050064199TPNB050064268

$ echo "0001349000174P00000012D-ATPNB050062184TPNB050063880
0001349000174P60000329C-ATPNB050064199TPNB050064268" | \ 
 
                          perl -ne' 

     s[(.)-(.)][.];
     ($a,$b,$i)=($1,$2,$-[0]); 

     @x=${a}gt$b?reverse$b..$a:$a..$b;
     for$x(@x){substr$_,$i,1,$x;print}
'
0001349000174P00000012DTPNB050062184TPNB050063880
0001349000174P00000012CTPNB050062184TPNB050063880
0001349000174P00000012BTPNB050062184TPNB050063880
0001349000174P00000012ATPNB050062184TPNB050063880
0001349000174P60000329CTPNB050064199TPNB050064268
0001349000174P60000329BTPNB050064199TPNB050064268
0001349000174P60000329ATPNB050064199TPNB050064268



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
0
Reply someone4 (105) 7/1/2008 11:28:23 AM

On Jul 1, 2:59=A0am, inja...@gmail.com wrote:
> Hi,
> I have the following file
> swadmin@tb142:/rangedoms1/working/
> CRST_OVERLAY_ENHANCE_Analysis_RNGCTRL_DEV> cat exp_aovr_send_new.dat
> 0001349000174P00000012D-ATPNB050062184TPNB050063880
> 0001349000174P60000329C-ATPNB050064199TPNB050064268
>
> Now i need the above file in the below format i.e splitting up of
> range character 23 to 25 in each record.
> Resulting file
> ____________________
> 0001349000174P00000012DTPNB050062184TPNB050063880
> 0001349000174P00000012CTPNB050062184TPNB050063880
> 0001349000174P00000012BTPNB050062184TPNB050063880
> 0001349000174P00000012ATPNB050062184TPNB050063880
> 0001349000174P60000329CTPNB050064199TPNB050064268
> 0001349000174P60000329BTPNB050064199TPNB050064268
> 0001349000174P60000329ATPNB050064199TPNB050064268

Using awk:
jc@jc-ubuntu:~$ cat /tmp/sample.data
0001349000174P00000012D-ATPNB050062184TPNB050063880
0001349000174P60000329C-ATPNB050064199TPNB050064268

jc@jc-ubuntu:~$ awk 'BEGIN { FS=3D"-"; for(i=3D0; i<255; ++i)
asc[sprintf("%c",i)] =3D i; } /.-./ { p1=3Dsubstr($1,1,length($1)-1);
p2=3Dsubstr($2,2); chhi=3Dasc[substr($1,length($1))];
chlo=3Dasc[substr($2,1,1)]; for(; chhi>=3Dchlo; chhi--) { print p1
sprintf("%c",chhi) p2 } }' < /tmp/sample.data
0001349000174P00000012DTPNB050062184TPNB050063880
0001349000174P00000012CTPNB050062184TPNB050063880
0001349000174P00000012BTPNB050062184TPNB050063880
0001349000174P00000012ATPNB050062184TPNB050063880
0001349000174P60000329CTPNB050064199TPNB050064268
0001349000174P60000329BTPNB050064199TPNB050064268
0001349000174P60000329ATPNB050064199TPNB050064268

AWK script formatted for readability:
BEGIN {
  FS=3D"-"
  for(i=3D0; i<255; ++i)
    asc[sprintf("%c",i)] =3D i
}

/.-./ {
  p1=3Dsubstr($1,1,length($1)-1)
  p2=3Dsubstr($2,2)
  chhi=3Dasc[substr($1,length($1))]
  chlo=3Dasc[substr($2,1,1)]
  for(; chhi>=3Dchlo; chhi--) {
    print p1 sprintf("%c",chhi) p2
  }
}
0
Reply shakahshakah (188) 7/1/2008 4:34:57 PM

3 Replies
63 Views

(page loaded in 0.083 seconds)

Similiar Articles:













7/30/2012 4:37:55 AM


Reply: