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?
 
simon3270Connect With a Mentor Commented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.