computing
  • 1

Solved How To Use Command Prompt To Edit CSV File

  • 1

I would like to

1) Delete the first three lines of a CSV file
2) Replace the new 1st header row (was the 4th row) with new headers on each of the columns.
3) Delete Columns 1, 5, 6, 7, 8, and 25.

I’ve tried some commands on own, including:

cat C14bOrigHdrs.csv | sed “1 d” > remove-row1.csv

cat remove-row1.csv | sed “1 d” > remove-row2.csv

cat remove-row2.csv | sed “1 d” > remove-row3.csv

sed -i ‘1s/.*/MRN & Pt Name,DOB,Pt Name,Txn Date,Txn Time,Item Code,Item Description,Order/RX#,User,Dept,AttendDocName,Description,Txn Type,NotesFromIssue,Issue Dose,Waste,UOM,Machine,Bin,Cost/Charge,Item Description – Total per Item per Patient (TPIPP),Net Disp (TPIPP),Net Waste (TPIPP),UOM,Net Charge (TPIPP),Delete,Delete,Delete,Delete,Delete,Delete,Delete,Delete/’ newheaders.csv

cut -d, -f 1–7,13,15-17,20,22-25 newheaders.csv > NeedToRemoveDuplicates.csv

Unfortuantely, I get an error message right away saying “‘cat’ is not recognized as an internal or external command, operable program or batch file.”

Any advice on what I’m doing wrong?

Thanks!

Share

1 Answer

  1. Ok, here’s a stab:
    :: ====begin prototype: output is in curr.dir as “testout.csv”. Input obviously “test.csv”
    @echo off & setlocal
    >testout.csv echo PT#,DOB,PT Name,Txn Date,Txn Time,Drug Name,Quantity
    for /f “skip=4 tokens=1-5,7,9 delims=,” %%a in (test.csv) do echo %%a,%%b,%%c,%%d,%%e,%%f,%%g>>testout.csv
    ::——– end script

    :: here is output from your sample:
    PT#,DOB,PT Name,Txn Date,Txn Time,Drug Name,Quantity
    “Pt: 111”,01/01/1950,John Doe,10/01/2019,01:00:00 AM,DRUGX,-2
    “Pt: 111”,01/01/1950,John Doe,10/01/2019,02:00:00 AM,DRUGX,-1
    “Pt: 111”,01/01/1950,John Doe,10/01/2019,03:00:00 AM,DRUGY,-4
    “Pt: 222”,02/02/1960,Jane Doe,10/01/2019,04:00:00 AM,DRUGZ,-5

    • 0