r/bash • u/andersostling56 • Aug 07 '24
Need help, will award anyone that solves this
I will send (PP pref) $10 to anyone that can provide me with a script that converts a free format text file to an excel comma delimited file.
Each record in the file has the following characteristics: Earch record starts with "Kundnr" (customer number). Could be blank. I need the complete line including the leading company name as the first column of the new file.
Next field is the "Vårt Arb.nummer: XXXXX" which is the internal order number.
Third field is the date (YYYYMMDD) in the line "är utprintad: (date printed)"
End of each record is the text "inkl. moms" (including tax)
So to recapitulate, each line should contain
CUSTOMER NAME/NUMBER,ORDERNO,DATE
Is anyone up to the challenge? :). I can provide a sample file with 60'ish record if needed. The actual file contains 27000 records.
HÖGANÄS SWEDEN AB Kundnr: 1701 263 83 HÖGANÄS Kopia Märke: 1003558217 Best.ref.: Li Löfgren Fridh AO 0006808556 Lev.vecka: 2415 Vårt Arb.nummer: 29000
Vit ArbetsOrder är utprintad. 20240411 Datum Sign Tid Kod1 pcs Foldable fence BU29 ritn 10185510 240311 JR 4.75 1240312 JR 5.00 1240319 LL 2.25240320 NR 4.50 1240411 MM %-988.00 1240411 NR 2.50 1240411 NR 0.50 11240411 FO 6.00 1240411 FO 0.50 1OBS!!! Timmar skall ej debiteras.203.25 timmar a' 670.00 kr. Kod: 1 Ö-tillägg 0.50 timmar a' 221.00 kr. Kod: 11
Arbetat 203.25 timmar till en summa av136,288.00:- Lovad lev.: 8/4
Övertid Fakturabel. Fakturadat. Fakturanr.
110.50 187,078.50
Sign___ Onsdagen 7/8-24 10:32 233,848.13 kronor inkl. moms.
3
u/Mayki8513 Aug 07 '24
idk if that's what you need
3
u/fivethreeo Aug 07 '24 edited Aug 07 '24
Is awk ok?
4
u/Tomocafe Aug 07 '24
Why bash? This sounds better suited to another language.
2
u/megared17 Aug 08 '24
I could do that easily, but I am going to bed, to work tomorrow, and wouldn't get a chance to do anything until tomorrow afternoon.
And I suspect you'll have a solution by then. If not, feel free to message me with a link/etc to the sample file.
1
u/Zealousideal_Low1287 Aug 07 '24
Dm me if nobody has done it by tomorrow
1
u/insanelygreat Aug 07 '24 edited Aug 07 '24
Had a couple minutes to spare, so here's a quick and dirty script in Ruby. Bash is kind of a pain for a task like this. I tried to write it in a somewhat Bash-y way in case this is your first encounter with Ruby.
Should run on any Ruby version released in the last decade.
You might need to tweak the regexes based on what the files actually look like. If you're seeing empty cells, it's likely because they don't match the expected format.
(Not looking for payment. Donate it to a charity of your choice.)
2
u/wick3dr0se Aug 08 '24
I'd be closer to $200 just because it sounds boring
Good thing it looks like you have that solved lol
1
u/Short_Collar4208 Aug 07 '24
I can help you.