file A
aa 22 48
ab 22 48
tcf 50 76
gf 50 76
h 89 100
yh 89 100
how can we split the file on the basis of common 2 and third column
output like
file A-1
aa 22 48
ab 22 48
file A-2
cf 50 76
gf 50 76
file A-3
th 89 100
yh 89 100
zaxxon
2
$> awk '$2==a && $3==b {print; next} {i++; if(NR==1){print "file A-"i}else{print "\nfile A-"i}; a=$2; b=$3; print}' infile
file A-1
aa 22 48
ab 22 48
file A-2
tcf 50 76
gf 50 76
file A-3
h 89 100
yh 89 100
1 Like
if separate output need be created then what can be the option
like file A-1,fileA-2 etc...
zaxxon
4
I don't like spaces in file names so I added an underscore:
awk '$2==a && $3==b {print >> "file_A-"i; next} {i++; a=$2; b=$3; print >> "file_A-"i}' infile
$> ll
total 24
drwxr-xr-x 2 root root 4096 29. Jul 14:06 .
drwxr-x--- 3 isau isau 4096 29. Jul 14:05 ..
-rw-r--r-- 1 root root 21 29. Jul 14:06 file_A-1
-rw-r--r-- 1 root root 23 29. Jul 14:06 file_A-2
-rw-r--r-- 1 root root 24 29. Jul 14:06 file_A-3
-rw-r--r-- 1 root root 68 29. Jul 14:05 infile
$> cat file_A-1
aa 22 48
ab 22 48
$> cat file_A-2
cf 50 76
gf 50 76
$> cat file_A-3
th 89 100
yh 89 100