Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Search & Replace - Between Files.

26 views
Skip to first unread message

harpre...@gmail.com

unread,
Jun 4, 2014, 6:00:33 PM6/4/14
to
Hello All,

There are two files.

File1

US60001.file1_rpt.d06042014.20140604231856
US70001.file2_rpt.d06042014.20140604231832
US80001.file3_rpt.d06042014.
US90001.file4_rpt.d06042014.20140604231856

File2

US60001.file1_rpt.d06042014.20140604231856
US70001.file2_rpt.d06042014.20140604231832
US80001.file3_rpt.d06042014.20140604231824
US90001.file4_rpt.d06042014.20140604231856
US80001.file3_rpt.d06042014.20140604231827

Sometimes, data in file1 comes without timestamp at the end. (Example is line 3 in file1). In such cases, I want to remove respective timestamp from fil2 as well for same filenames from file1

Expected Output for file2

File2

US60001.file1_rpt.d06042014.20140604231856
US70001.file2_rpt.d06042014.20140604231832
US80001.file3_rpt.d06042014.
US90001.file4_rpt.d06042014.20140604231856
US80001.file3_rpt.d06042014.

File2 can have multiple occurences of filename in file1.

How can I achieve this?

harpre...@gmail.com

unread,
Jun 4, 2014, 6:16:27 PM6/4/14
to
Correction. I also want to replace "dots" from the end of such files.

Expected Output for file2

File2

US60001.file1_rpt.d06042014.20140604231856
US70001.file2_rpt.d06042014.20140604231832
US80001.file3_rpt.d06042014
US90001.file4_rpt.d06042014.20140604231856
US80001.file3_rpt.d06042014

Janis Papanagnou

unread,
Jun 4, 2014, 6:36:06 PM6/4/14
to
On 05.06.2014 00:00, harpre...@gmail.com wrote:
> Hello All,
>
> There are two files.
[...]
> How can I achieve this?
>

You're giving the impression that you want others do your job.

Inspecting Dan Espen's replay to your "Comparing files" thread
and your answer I can't help suggesting to hire a specialist or
pay a consultant.

Janis

harpre...@gmail.com

unread,
Jun 4, 2014, 6:45:03 PM6/4/14
to
Janis,

I dont understand this. I am not asking the entire automation to be done here. There are couple of points where I am stuck or need some advise.

I am not asking the entire work to be done here. Just some points where I need assistance.

Sorry if you felt that way. Even I dont like asking so many questions but I know it will be stupid if I dont clarify my doubts or ask for advise.

frank.w...@gmail.com

unread,
Jun 4, 2014, 6:53:28 PM6/4/14
to
From harpreet.noni:
>I dont understand this. I am not asking the entire
>automation to be done here. There are couple of points
>where I am stuck or need some advise.

You did not specify any specific points you wanted help
with. I appears to me that you presented sn entire
problem to be solved.

There some cases where this is acceptable. If this is a
non-profit project then it is acceptable, but if it is
for a commercial function then you are keeping a
programmer out of work.

Frank

harpre...@gmail.com

unread,
Jun 4, 2014, 7:07:58 PM6/4/14
to
Ok. Sorry guys. Its not an entire problem to be solved but part of one. It's not non-profit work. Just some value addition to my client.

Thanks

Kenny McCormack

unread,
Jun 4, 2014, 7:08:46 PM6/4/14
to
In article <146691cbb2c$frank.w...@gmail.com>,
Heh heh. Funny on so many levels...

--
This is the GOP's problem. When you're at the beginning of the year
and you've got nine Democrats running for the nomination, maybe one or
two of them are Dennis Kucinich. When you have nine Republicans, seven
or eight of them are Michelle Bachmann.

Kaz Kylheku

unread,
Jun 4, 2014, 7:46:09 PM6/4/14
to
On 2014-06-04, harpre...@gmail.com <harpre...@gmail.com> wrote:
> Hello All,
>
> There are two files.
>
> File1
>
> US60001.file1_rpt.d06042014.20140604231856
> US70001.file2_rpt.d06042014.20140604231832
> US80001.file3_rpt.d06042014.
> US90001.file4_rpt.d06042014.20140604231856
>
> File2
>
> US60001.file1_rpt.d06042014.20140604231856
> US70001.file2_rpt.d06042014.20140604231832
> US80001.file3_rpt.d06042014.20140604231824
> US90001.file4_rpt.d06042014.20140604231856
> US80001.file3_rpt.d06042014.20140604231827
>
> Sometimes, data in file1 comes without timestamp at the end. (Example is line
> 3 in file1). In such cases, I want to remove respective timestamp from fil2
> as well for same filenames from file1
>
> Expected Output for file2

TXR (Solaris 10 x86 binary of Version 89 now available!)

http://www.nongnu.org/txr

Very simple:

@(bind timestamp-set @(hash :equal-based))
@(repeat)
@f1.@f2.@f3.@{timestamp /.+/}
@(do (sethash timestamp-set (list f1 f2 f3) t))
@(end)
@(next)
@(repeat)
@f1.@f2.@f3.@timestamp
@(do (put-line `@f1.@f2.@f3@(if (inhash timestamp-set (list f1 f2 f3))
`.@timestamp` "")`))
@(end)

$ txr timestamp.txr file1 file2

Kaz Kylheku

unread,
Jun 4, 2014, 7:48:28 PM6/4/14
to
On 2014-06-04, Kenny McCormack <gaz...@shell.xmission.com> wrote:
> In article <146691cbb2c$frank.w...@gmail.com>,
> <frank.w...@gmail.com> wrote:
>>From harpreet.noni:
>> >I dont understand this. I am not asking the entire
>> >automation to be done here. There are couple of points
>> >where I am stuck or need some advise.
>>
>>You did not specify any specific points you wanted help
>>with. I appears to me that you presented sn entire
>>problem to be solved.
>>
>>There some cases where this is acceptable. If this is a
>>non-profit project then it is acceptable, but if it is
>>for a commercial function then you are keeping a
>>programmer out of work.
>
> Heh heh. Funny on so many levels...

I thought so too: for instance, non-profit crap tends to keep everyone
involved out of work, first of all.

"If you're not getting paid either, you're my friend and I will help you!"

:)

harpre...@gmail.com

unread,
Jun 4, 2014, 8:08:41 PM6/4/14
to
Thanks Kaz. But I need to do this in Unix code.I dont think I am allowed to use anything else.

Kenny McCormack

unread,
Jun 4, 2014, 8:10:57 PM6/4/14
to
In article <201406041...@kylheku.com>,
Kaz Kylheku <k...@kylheku.com> wrote:
...
>TXR (Solaris 10 x86 binary of Version 89 now available!)
>
>http://www.nongnu.org/txr
>
>Very simple:
>
>@(bind timestamp-set @(hash :equal-based))
>@(repeat)
>@f1.@f2.@f3.@{timestamp /.+/}
>@(do (sethash timestamp-set (list f1 f2 f3) t))
>@(end)
>@(next)
>@(repeat)
>@f1.@f2.@f3.@timestamp
>@(do (put-line `@f1.@f2.@f3@(if (inhash timestamp-set (list f1 f2 f3))
> `.@timestamp` "")`))
>@(end)
>
>$ txr timestamp.txr file1 file2
>US60001.file1_rpt.d06042014.20140604231856
>US70001.file2_rpt.d06042014.20140604231832
>US80001.file3_rpt.d06042014
>US90001.file4_rpt.d06042014.20140604231856
>US80001.file3_rpt.d06042014

Yaknow...

If the goal is to get the OPs thinking - getting them to solve the problem
on their own - then I think posting solutions in TXR (or other, let's be
nice and say, non-mainstream, languages) is a good idea. Better than spoon
feeding them a solution in, say, AWK or shell - as is the usual norm in
these groups.

Somewhat related to the above, I often (intentionally) post solutions which
are, shall we say, about 3/4ths right. The idea is to leave a little for
the reader to work out on his own. Then, of course, I get slagged by the
other regs for not giving a full, complete, spoon-feed answer.

So, I say, keep the TXR solutions coming...

--

There are many self-professed Christians who seem to think that because
they believe in Jesus' sacrifice they can reject Jesus' teachings about
how we should treat others. In this country, they show that they reject
Jesus' teachings by voting for Republicans.

Dave Sines

unread,
Jun 5, 2014, 11:57:44 AM6/5/14
to
[ requirement clarification elsewhere in thread: omit trailing dots ]

>
> File2 can have multiple occurences of filename in file1.

Read File1, create an array indexed by strings formed from the first three
fields of each line which ends with a dot.

Read File2. If a string formed from the first three fields of a line exists
as an index in the array generated while reading File1, replace the current
input record with the string.

awk '
BEGIN { FS = "." }
{ s = $1 "." $2 "." $3 }
NR == FNR {
if ($NF == "")
hold[s]
next
}
(s in hold) { $0 = s }
{ print }
' File1 File2

harpre...@gmail.com

unread,
Jun 7, 2014, 8:06:21 AM6/7/14
to
Thanks Dave. Appreciate your help
0 new messages