Tag Info

New answers tagged


{ BS=$(($(wc -c <file) * $P / 100)) dd count=1 bs="$BS" >file1; cat } <file >file2 2>/dev/null ...should work for this simple case because you're only splitting once - and so probably split is a little overkill. So long as the file is seekable, dd will only do a single read() on <stdin, and so cat is left to begin its read() at ...


You could use csplit to split into two pieces (using any percentage) e.g. first piece - first 20% of lines, second piece - the remaining 80% of lines: csplit file $(( $(wc -l < file) * 2 / 10 + 1)) $(wc -l < file) : total number of lines 2 / 10 : percentage +1 : add one line because csplit splits up to but not including line N You can only split ...


Simple awk command: awk 'NR%2==0{ print $0 > "File "++i }' RS='"' file RS defines " as record separator and NR is the record number. If the record number was modulo of 2 (because we have another first " for records), then print the record($0) into a File #.


You can do: awk -v RS=\" -v ORS= \ '{ sub(/^\n*/,"");sub(/\n*$/,""); }; /^\n*$/ { next;}; { if(strcnt==0) { print $0 >"file1"; strcnt++;} else { print $0 >"file2"; }; }' file


If the opening quote is always at the beginning of the line, csplit will work just fine like this: bash$ csplit /tmp/data '/^"/' That produces files called xx00, etc. Note, your example removes the quotation marks and this doesn't. You'd need a command line sed to do that: bash$ for file in xx* ; do { sed 's/^"//;s/"$//;' ${file} >x${file}; } ; done


With GNU awk awk -v RS='"[[:space:]]*"' ' {sub(/^"|"[[:space:]]*$/, "");print > "output." ++n; close("output." n)}' file.txt

Top 50 recent answers are included