gow awk to split file in windows

I have a csv file in wondows and I have installed GOW to allow me to use linux commands to split a file

I need to copy the header record and place that into each split file and have that split file go to a split directory

so my file is here>>
data/current load/testing.csv


I would need to have it split to the following directory
data/current load/spit/

and then I need to make sure I have the header record copied over to each split file

what I have so far is
so here is my input csv file name testing.csv

head -n 1 "F:data\current load"\testing.csv > header_file

tail -n +2 "F:data\current load"\testing.csv > data_file

split -d --lines=1000 "F:data\current load"\data_file "F:data\current load\split"\data_file

at this point i have created all the split data files


ls split\data*

my set of instructions are for each file

copy header_file split\*

cat split\data_file16 >> split\header_file

rename split\header_file split\data_file16.csv

rm split\header_file


so first I am looking for a way to read all the data files names to be able to loop through my second part of the process

and ideally I am sure there must be a single line to do the same thing that I want to do using some sort of awk command
LVL 2
Jayesh AcharyaTechnichal ConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

simon3270Commented:
This will split the file into 100-line chunks, printing the first line of the input file to each of the output files, with the output files having a fixed prefix and a numeric suffix (e.g. aaa0000 aa0001 aaa0002 etc):
awk 'BEGIN{lc=0;pref="aaa";fc=0}
NR == 1{hdr=$0;next}
{if (lc == 0){fn=sprintf("%s%04d",pref,fc);print hdr > fn}
print $0 > fn
lc=lc+1
if (lc == 100){lc=0;fc=fc+1}}' input_file_name

Open in new window

Change the prefix value (currently pref="aaa"), the number of digits in the suffix (currently 4, in "%04d") and the number of lines in each output file (lc == 100) as you wish.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Seth SimmonsSr. Systems AdministratorCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: simon3270 (https:#a42439978)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

seth2740
Experts-Exchange Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.