Merging two text files
Discussion
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
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
If sticking in Windows, you want to download the following utilities from GnuWin32:
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.
- awk
- cat
- sed
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.
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
What's the matter with you? Good grief.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
Edited by Driller on Friday 19th December 22:29
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."?
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
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.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.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 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.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
Do you just want me to apologise? I'm sorry. Now will you go away?
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.
I hope that helps.
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.I thought it was clear that this would have been from another thread, so the link should help you.
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff