Visit Our UNIX and Linux User Community


Task


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Task
# 22  
Old 06-08-2011
Hi bartu11,

Sorry, but I have given another update on the task.
I was told this should be last change. Thanks thousand times.

this is the new INPUT: as oyu can see there was added one more column(last in red) , so we search for rows with 12 columns + time format in green in case of rows needed to be duplicited is slightly different
Code:
H:                            EURS100                                    00440000000050.00000000000000010100000075 FR0000045072                            2ACAp                20110608-08:06:13BNABFRPP            PA BNABFRPP            PARBFRPP                                                  #A
H:                            EURB100                                    00440000000050.00000000000000010100000096 FR0000045072                            1ACAp                20110608-08:06:13BNABFRPP            PA BNABFRPP            PARBFRPP                                                  #R
H:                            EUR1B101                B101               10440000000420.00000000000000099100000098 FR0000120628                            1CSp                 2011-06-08 10:41:26TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #A 34633539544
H:                            EUR1S101                S101               10440000000420.00000000000000099100000099 FR0000120628                            2CSp                 2011-06-08 10:41:26TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #R 34633539544

this is desired OUTPUT, as you can see time format in green is slightly different then rest, so it will have to be converted + time of the duplicated rows should be calculated from the last column in red(milicesonds since midnight).
Code:
H:                            EURS100                                    00440000000050.00000000000000010100000075 FR0000045072                            2ACAp                20110608-08:06:13BNABFRPP            PA BNABFRPP            PARBFRPP                                                  #A
H:                            EURB100                                    00440000000050.00000000000000010100000096 FR0000045072                            1ACAp                20110608-08:06:13BNABFRPP            PA BNABFRPP            PARBFRPP                                                  #R
H:                            EURB101                                    00440000000420.00000000000000099100000098 FR0000120628                            1CSp                 20110608-09:36:13TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #A 34633539544
H:                            EURS101                                    00440000000420.00000000000000099100000099 FR0000120628                            2CSp                 20110608-09:36:13TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #R 34633539544
H:                            EUR1B101                B101               10440000000420.00000000000000099100000098 FR0000120628                            1CSp                 20110608-10:41:26TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #A 34633539544
H:                            EUR1S101                S101               10440000000420.00000000000000099100000099 FR0000120628                            2CSp                 20110608-10:41:26TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #R 34633539544


Last edited by hernand; 06-08-2011 at 06:17 PM..
# 23  
Old 06-08-2011
No need to apologize Smilie Try:
Code:
#!/usr/bin/perl
open I, "$ARGV[0]";
@x=<I>;
$i=0;
for (@x){
  s/ +$//;
  $t=$_;
  @s=split / +/;
  if ($#s==11){
    $i=1;
    s/([^ ]+ +EUR)1([SB]\d+ +)[^ ]+( +)1/$1$2     ${3}0/;
    /([^ ]+ +){5}(\d+)-(\d+)-(\d+) (\d+:\d+:\d+)/;
    $d="$2$3$4";
    $date2="$d-$5";
    /(\d+)$/;
    $h=int($1/3600000000);
    $m=int(60*($1/3600000000-$h));
    $sek=int(60*(60*($1/3600000000-$h)-$m));
    $time=sprintf "%02d:%02d:%02d",$h,$m,$sek;
    $date1=$d . "-" . $time;
    s/(([^ ]+ +){5})\d+-\d+-\d+ \d+:\d+:\d+/$1$date1/;
    $t=~s/(([^ ]+ +){6})\d+-\d+-\d+ \d+:\d+:\d+/$1$date2/;
    $s.=$_;
    $q.=$t;
  } elsif ($i) {
    $i=0;
    $s.=$q;
    $s.=$t;
  } else {
    $s.=$t;
  }
}
$s.=$q if $i;
print $s;


Last edited by bartus11; 06-08-2011 at 06:41 PM.. Reason: Removed some unnecessary lines...
This User Gave Thanks to bartus11 For This Post:
# 24  
Old 06-08-2011
Hi , output was different

then I found out that I mislead you because now we have 13 columns
as you can see highighted there is one additional space between date and time in the INPUT:

Code:
H:                            EURS100                                    00440000000050.00000000000000010100000075 FR0000045072                            2ACAp                20110608-08:06:13BNABFRPP            PA BNABFRPP            PARBFRPP                                                  #A
H:                            EURB100                                    00440000000050.00000000000000010100000096 FR0000045072                            1ACAp                20110608-08:06:13BNABFRPP            PA BNABFRPP            PARBFRPP                                                  #R
H:                            EUR1B101                B101               10440000000420.00000000000000099100000098 FR0000120628                            1CSp                 2011-06-08 10:41:26TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #A 34633539544
H:                            EUR1S101                S101               10440000000420.00000000000000099100000099 FR0000120628                            2CSp                 2011-06-08 10:41:26TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #R 34633539544

# 25  
Old 06-08-2011
Try this then:
Code:
#!/usr/bin/perl
open I, "$ARGV[0]";
@x=<I>;
$i=0;
for (@x){
  s/ +$//;
  $t=$_;
  @s=split / +/;
  if ($#s==12){
    $i=1;
    s/([^ ]+ +EUR)1([SB]\d+ +)[^ ]+( +)1/$1$2     ${3}0/;
    /([^ ]+ +){5}(\d+)-(\d+)-(\d+) (\d+:\d+:\d+)/;
    $d="$2$3$4";
    $date2="$d-$5";
    /(\d+)$/;
    $h=int($1/3600000000);
    $m=int(60*($1/3600000000-$h));
    $sek=int(60*(60*($1/3600000000-$h)-$m));
    $time=sprintf "%02d:%02d:%02d",$h,$m,$sek;
    $date1=$d . "-" . $time;
    s/(([^ ]+ +){5})\d+-\d+-\d+ \d+:\d+:\d+/$1$date1/;
    $t=~s/(([^ ]+ +){6})\d+-\d+-\d+ \d+:\d+:\d+/$1$date2/;
    $s.=$_;
    $q.=$t;
  } elsif ($i) {
    $i=0;
    $s.=$q;
    $s.=$t;
  } else {
    $s.=$t;
  }
}
$s.=$q if $i;
print $s;

This User Gave Thanks to bartus11 For This Post:
# 26  
Old 06-08-2011
Thanks, works perfectly.

I wast just given the last change. This is definitely the last change that they request.They have sweared that this is the LAST change.
We need to delete 1 hour from the time highighted in red.
it was "10:41:26" but we need "09:41:26"

Million thanks

Code:
H:                            EURS100                                    00440000000050.00000000000000010100000075 FR0000045072                            2ACAp                20110608-08:06:13BNABFRPP            PA BNABFRPP            PARBFRPP                                                  #A
H:                            EURB100                                    00440000000050.00000000000000010100000096 FR0000045072                            1ACAp                20110608-08:06:13BNABFRPP            PA BNABFRPP            PARBFRPP                                                  #R
H:                            EUR1B101                B101               10440000000420.00000000000000099100000098 FR0000120628                            1CSp                 2011-06-08 10:41:26TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #A 34633539544
H:                            EUR1S101                S101               10440000000420.00000000000000099100000099 FR0000120628                            2CSp                 2011-06-08 10:41:26TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #R 34633539544

this is desired OUTPUT, as you can see time format in green is slightly different then rest, so it will have to be converted + time of the duplicated rows should be calculated from the last column in red(milicesonds since midnight).
Code:
H:                            EURS100                                    00440000000050.00000000000000010100000075 FR0000045072                            2ACAp                20110608-08:06:13BNABFRPP            PA BNABFRPP            PARBFRPP                                                  #A
H:                            EURB100                                    00440000000050.00000000000000010100000096 FR0000045072                            1ACAp                20110608-08:06:13BNABFRPP            PA BNABFRPP            PARBFRPP                                                  #R
H:                            EURB101                                    00440000000420.00000000000000099100000098 FR0000120628                            1CSp                 20110608-09:36:13TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #A 34633539544
H:                            EURS101                                    00440000000420.00000000000000099100000099 FR0000120628                            2CSp                 20110608-09:36:13TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #R 34633539544
H:                            EUR1B101                B101               10440000000420.00000000000000099100000098 FR0000120628                            1CSp                 20110608-09:41:26TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #A 34633539544
H:                            EUR1S101                S101               10440000000420.00000000000000099100000099 FR0000120628                            2CSp                 20110608-09:41:26TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #R 34633539544


Last edited by hernand; 06-08-2011 at 07:23 PM..
# 27  
Old 06-08-2011
Try this one:
Code:
#!/usr/bin/perl
open I, "$ARGV[0]";
@x=<I>;
$i=0;
for (@x){
  s/ +$//;
  $t=$_;
  @s=split / +/;
  if ($#s==12){
    $i=1;
    s/([^ ]+ +EUR)1([SB]\d+ +)[^ ]+( +)1/$1$2     ${3}0/;
    /([^ ]+ +){5}(\d+)-(\d+)-(\d+) (\d+)(:\d+:\d+)/;
    $d="$2$3$4";
    $h2=sprintf "%02d", ($5-1);
    $date2="$d-$h2$6";
    /(\d+)$/;
    $h=int($1/3600000000);
    $m=int(60*($1/3600000000-$h));
    $sek=int(60*(60*($1/3600000000-$h)-$m));
    $time=sprintf "%02d:%02d:%02d",$h,$m,$sek;
    $date1=$d . "-" . $time;
    s/(([^ ]+ +){5})\d+-\d+-\d+ \d+:\d+:\d+/$1$date1/;
    $t=~s/(([^ ]+ +){6})\d+-\d+-\d+ \d+:\d+:\d+/$1$date2/;
    $s.=$_;
    $q.=$t;
  } elsif ($i) {
    $i=0;
    $s.=$q;
    $s.=$t;
  } else {
    $s.=$t;
  }
}
$s.=$q if $i;
print $s;

These 2 Users Gave Thanks to bartus11 For This Post:
# 28  
Old 06-08-2011
thanks

I accidentaly removed one change from my previous post and realized just now. (Time decreasing worked fine.)
highlighted in blue font is the change that I removed accidentally.
Also two lines are swapped(S101 first, B101 second - but this is not so critical)
I'm really really SORRY, I don't do this on purpose. Please check

Code:
H:                            EURS100                                    00440000000050.00000000000000010100000075 FR0000045072                            2ACAp                20110608-08:06:13BNABFRPP            PA BNABFRPP            PARBFRPP                                                  #A
H:                            EURB100                                    00440000000050.00000000000000010100000096 FR0000045072                            1ACAp                20110608-08:06:13BNABFRPP            PA BNABFRPP            PARBFRPP                                                  #R
H:                            EUR1B101                B101               10440000000420.00000000000000099100000098 FR0000120628                            1CSp                 2011-06-08 10:41:26TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #A 34633539544
H:                            EUR1S101                S101               10440000000420.00000000000000099100000099 FR0000120628                            2CSp                 2011-06-08 10:41:26TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #R 34633539544


Code:
H:                            EURS100                                    00440000000050.00000000000000010100000075 FR0000045072                            2ACAp                20110608-08:06:13BNABFRPP            PA BNABFRPP            PARBFRPP                                                  #A
H:                            EURB100                                    00440000000050.00000000000000010100000096 FR0000045072                            1ACAp                20110608-08:06:13BNABFRPP            PA BNABFRPP            PARBFRPP                                                  #R
H:                            EURB101                                    00440000000420.00000000000000099100000098 FR0000120628                            1CSp                 20110608-09:36:13TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #A 34633539544
H:                            EURS101                                    00440000000420.00000000000000099100000099 FR0000120628                            2CSp                 20110608-09:36:13TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #R 34633539544
H:                            EUR1S101                S101               10440000000000.00099000042000000100000099 FR0000120628                            2CSp                 20110608-09:41:26TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #R 34633539544
H:                            EUR1B101                B101               10440000000000.00099000042000000100000098 FR0000120628                            1CSp                 20110608-09:41:26TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #A 34633539544


Last edited by hernand; 06-08-2011 at 07:42 PM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #567
Difficulty: Medium
The ternary if-then-else operator generally has the following syntax: E ? X : Y where E is a Boolean expression and if true, the statement is assigned the value Y.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automate a task

Dear All, I am relatively new to UNIX and wanted to accomplish a simple task which should be automated. That's why I need your help. I shall briefly describe what I want. Basically, there is a process (X) (related to a particular software which I am using in my system) which automatically... (5 Replies)
Discussion started by: Samiran Dam
5 Replies

2. Homework & Coursework Questions

[HELP] Easy task

I have a simple task for my school work. I'm new with unix, so i need help. I need to write a scenario. Task is. From created txt file read first 3 words and create a 3 catalogs with those 3 words. 2 of those new catalogs should be transferred to other directory. If someone could help me just... (1 Reply)
Discussion started by: justynykas
1 Replies

3. Shell Programming and Scripting

task

Hi all, I'm newbie and stuck here. Thanks for any help. Input(txt file) a b X c d Y e f Z g h W Requested output: a b X Y c d Y X e f Z W g h W Z Please use code tags when posting data and code samples! (10 Replies)
Discussion started by: hernand
10 Replies

4. Shell Programming and Scripting

last task for my script

hi, infile- create table salary ( occupation_code char(40), earnings decimal(10,2), occ_yearend integer ); outfile- salary:create table salary salary:( occupation_code char(40), salary: earnings decimal(10,2), salary: occ_yearend integer salary:); Thanks. (4 Replies)
Discussion started by: dvah
4 Replies

5. Shell Programming and Scripting

Need a help to automate a task

I need to automate a manual task using shell scripting. The scenario is like :- #!/usr/bin/sh echo "please enter the name of the lab server to test ..." read s ssh $s This is peace of the script which will allow me to login to another server using "ssh". I have a conf file which is having... (4 Replies)
Discussion started by: Renjesh
4 Replies

6. Shell Programming and Scripting

Parse an XML task list to create each task.xml file

I have an task definition listing xml file that contains a list of tasks such as <TASKLIST <TASK definition="Completion date" id="Taskname1" Some other <CODE name="Code12" <Parameter pname="Dog" input="5.6" units="feet" etc /Parameter> <Parameter... (3 Replies)
Discussion started by: MissI
3 Replies

7. Shell Programming and Scripting

Need help with a manual task

I have an ASCII file that I receive on a monthly bases that is fixed length. I break the file into separate files based on a 5 character numerical sequence. I have 20 different sequences I have to find. the input file looks something like this xy-ins 2008yuthnrlsinrthsntwilgrha33260001... (4 Replies)
Discussion started by: jcalisi
4 Replies

8. Shell Programming and Scripting

comment and Uncomment single task out of multiple task

I have a file contains TASK gsnmpproxy { CommandLine = $SMCHOME/bin/gsnmpProxy.exe } TASK gsnmpdbgui { CommandLine = $SMCHOME/bin/gsnmpdbgui.exe I would like to comment and than uncomment specific task eg TASK gsnmpproxy Pls suggest how to do in shell script (9 Replies)
Discussion started by: madhusmita
9 Replies

9. UNIX for Dummies Questions & Answers

process vs task

Hi, I am new to this forum and unix too. I have just started learning unix. As I was going through the first chapter, I read that unix is multitasking, multiprogramming, multiprocessing and multiuser OS. My question is: Is there any difference between a TASK and a PROCESS. How are PROCESS... (2 Replies)
Discussion started by: hana
2 Replies

Featured Tech Videos