This script will be useful if you require to split a huge file based on number of lines or records. Normal file splitters available in the market split the file based on the size (byte, KB, MB) which cannot be used to split based on number of lines or records.
Steps to use the script:
- Save the below script as lsplit.ksh
propDIR=./propFile=$propDIR/SSNRange.txt.propinpFile=$1datestartLineNo=1count=1whilereadlinedostartLineNo=`echo$line |cut-f1 -d,`endLineNo=`echo$line |cut-f2 -d,`if["$endLineNo"!=""-a"$startLineNo"!=""];thenecho"Cut here from $startLineNo to $endLineNo"sed-n"$startLineNo","$endLineNo"p $inpFile > $inpFile.split.$countcount=`expr$count + 1`fidone< $propFiledate - Create a properties file SSNRange.txt.prop which would contain the range of records or lines. Example of properties file is as follows
1231,400401,15041505, 7000 - Run the script1
$ lsplit.ksh infile.txt - Three output files will be created
- infile.txt.split.1 –> Creates a file with first 400 lines
- infile.txt.split.2 –> Creates a file with lines starting from 401 to 1504
- infile.txt.split.3 –> Creates a file with lines starting from 1505 to 7000
- File is split based on line numbers are records.
- No manual editing is required the correct the first and last records
- Easy to handle it in batch
没有评论:
发表评论