Merging two text files

Author
Discussion

ArsE92

Original Poster:

21,007 posts

186 months

Thursday 18th December 2014
quotequote all
Chaps

I need to merge two very similar text files into one output file on a regular basis (on Windows), and I need to automate it. Usually this would be pretty straight-forward using basic copy commands but I need to make a few changes to the final output.

Both files have a similar header, but I only need to keep one of them.

Both files have a record count at the end, but I need to discard one and make the final one correct.

Not so easy now!

So, in pseudo code, I think I need to:

copy file1 to variable1
copy file2 to variable2
concatenate variable1 & variable2 into variable3
find and delete the second instance of the header in variable3
find and delete the first record count in variable3
find and delete the second record count in variable3
count records and create a new record count line in variable3
write variable3 to output.txt
profit

It's been a while since I've done any scripting but I used to be pretty good with batch files and I'm picking up a bit of Powershell as I go along.

Any thoughts on what I can best use and how I can achieve the above? I could probably spin up a Linux VM just for this if it really was the best solution, but I'm not great with Linux.

Thanks in advance

eltawater

3,107 posts

178 months

Friday 19th December 2014
quotequote all
If sticking in Windows, you want to download the following utilities from GnuWin32:

  • awk
  • cat
  • sed
Then do this:

sed "1d;$d" file1.txt > file1trim.txt
sed "$d" file2.txt > file2trim.txt
cat file2trim.txt file1trim.txt > combined.txt

awk "END { print NR-1 \" records\"}" combined.txt >> combined.txt

Formatting on the last line might be a bit screwy, hope it's got through the filters ok.

ArsE92

Original Poster:

21,007 posts

186 months

Friday 19th December 2014
quotequote all
Thanks - just downloading gnuwin32 now and will have a play this weekend. smile

Driller

8,310 posts

277 months

Friday 19th December 2014
quotequote all
Has Anyone Really Been Far Even as Decided to Use Even Go Want to do Look More Like?

chris333

1,034 posts

238 months

Friday 19th December 2014
quotequote all
Driller said:
Has Anyone Really Been Far Even as Decided to Use Even Go Want to do Look More Like?
no

ArsE92

Original Poster:

21,007 posts

186 months

Friday 19th December 2014
quotequote all
laugh

Driller

8,310 posts

277 months

Friday 19th December 2014
quotequote all
So it's a group effort eh? Nice.

You post up an idea and someone just comes along and pisses on it.

You're rude and childish however many there are of you.

Oh and Mr Arse 75 months and 20,000 odd posts, it's all very clear laugh

Edited by Driller on Friday 19th December 22:29

ArsE92

Original Poster:

21,007 posts

186 months

Friday 19th December 2014
quotequote all
Driller said:
So it's a group effort eh? Nice.

You post up an idea and someone just comes along and pisses on it.

You're rude and childish however many there are of you.

Oh and Mr Arse 75 months and 20,000 odd posts, it's all very clear laugh

Edited by Driller on Friday 19th December 22:29
What's the matter with you? Good grief.

Driller

8,310 posts

277 months

Friday 19th December 2014
quotequote all
What's the matter with me, have you no sense of etiquette?

What exactly does "Has Anyone Really Been Far Even as Decided to Use Even Go Want to do Look More Like" mean?

ArsE92

Original Poster:

21,007 posts

186 months

Friday 19th December 2014
quotequote all
Driller said:
What's the matter with me, have you no sense of etiquette?

What exactly does "Has Anyone Really Been Far Even as Decided to Use Even Go Want to do Look More Like" mean?
Well you posted it above.

Driller

8,310 posts

277 months

Saturday 20th December 2014
quotequote all
Oh that's rich, so if I do something objectionable to you, you'll just do nothing right?

I posted asking people's opinion on something (maybe not the most profound subject but so what?) and you reply with nonsensical gobbledygook effectively going "BLAH, BLAH, BLAH" in my face and then you leave the thread with no other comment, like a hound having given a lamp post a perfunctory sniff before pissing on it and moving on to the next one.

Are you some sort of delinquent verbal graffiti artist? Do your 20,000 posts tell fluorescent stories of "I was 'ere" and ""My bluds say the skets round here are nuff deep."?





Edited by Driller on Tuesday 6th January 08:20

littleredrooster

5,523 posts

195 months

Saturday 20th December 2014
quotequote all
Driller said:
I posted asking people's opinion on something...
No you didn't, you posted this:
driller said:
Has Anyone Really Been Far Even as Decided to Use Even Go Want to do Look More Like?
That is what you actually posted. I don't think any of us knows what it means so please don't go on an uncalled-for rant.

Driller

8,310 posts

277 months

Saturday 20th December 2014
quotequote all
littleredrooster said:
Driller said:
I posted asking people's opinion on something...
No you didn't, you posted this:
driller said:
Has Anyone Really Been Far Even as Decided to Use Even Go Want to do Look More Like?
That is what you actually posted. I don't think any of us knows what it means so please don't go on an uncalled-for rant.
http://www.pistonheads.com/gassing/topic.asp?h=0&a...

I thought it was clear that this would have been from another thread, so the link should help you.

Edited by Driller on Saturday 20th December 12:37

ArsE92

Original Poster:

21,007 posts

186 months

Saturday 20th December 2014
quotequote all
Driller said:
littleredrooster said:
Driller said:
I posted asking people's opinion on something...
No you didn't, you posted this:
driller said:
Has Anyone Really Been Far Even as Decided to Use Even Go Want to do Look More Like?
That is what you actually posted. I don't think any of us knows what it means so please don't go on an uncalled-for rant.
http://www.pistonheads.com/gassing/topic.asp?h=0&a...

I thought it was clear that this would have been from another thread, so the link should help you.

Edited by Driller on Saturday 20th December 12:37
Driller, seriously. You posted something in The Lounge and I made a throwaway comment. Are you really that sensitive that you felt the need to browse my profile and come and comment on another thread that I'd started in another sub-forum?

Do you just want me to apologise? I'm sorry. Now will you go away?

Driller

8,310 posts

277 months

Saturday 20th December 2014
quotequote all
Now will I go away? You're the one who came looking for it, I was minding my own business.

No I don't think I was being sensitive and 2 clicks to find a previous post does not equal your implied unjustified vendetta.

Let's drop it then.

TonyRPH

12,963 posts

167 months

Saturday 20th December 2014
quotequote all
And here I was, thinking that Driller had been overcome with Novocaine. wobble

wavey Driller.


mike9009

6,918 posts

242 months

Saturday 20th December 2014
quotequote all
ArseDriller having a lovers tiff? Kiss and make up lads, life is too short....

TheEnd

15,370 posts

187 months

Saturday 20th December 2014
quotequote all
Besides I've been further even more decided to used even go need to do more as anyone can. Can your really be far even as decided half as much to use go wish for that? My guess is that when one really been far even as decided once to use even go want, it is then that he has really been far even as decided to use even go want to do more like. It's common sense, bro.

I hope that helps.

TonyRPH

12,963 posts

167 months

Saturday 20th December 2014
quotequote all
/Thread.

Derailed.


littleredrooster

5,523 posts

195 months

Saturday 20th December 2014
quotequote all
Driller said:
littleredrooster said:
Driller said:
I posted asking people's opinion on something...
No you didn't, you posted this:
driller said:
Has Anyone Really Been Far Even as Decided to Use Even Go Want to do Look More Like?
That is what you actually posted. I don't think any of us knows what it means so please don't go on an uncalled-for rant.
http://www.pistonheads.com/gassing/topic.asp?h=0&a...

I thought it was clear that this would have been from another thread, so the link should help you.
Clear?? How on earth is anyone supposed to deduce that the gobbledegook was from a different poster on another thread? fk me - someone pass the Windolene please, my crystal ball's mucky!