Hi,
I'm new to linux & bash so please forgive my ignorance, just wondering if anyone can help.
I have a file (mainfile.txt) with comma deliminated values, like so:
$1 $2 $3
613212, 36, 57
613212, 36, 10
613212, 36, 10
677774, 36, 57
619900, 10, 10
i need to split this file into two files. Any entries where the first number ($1) is in more than once needs to go in file1.txt. Any entries that only occur once need to go into file2.txt, like so:
File1.txt
613212, 36, 57
613212, 36, 10
613212, 36, 10
File2.txt
677774, 36, 57
619900, 10, 10
Any solution to this problem would be greatly appreciated, no matter how implemented.
however, i would like to get experience using arrays so a solution incorporating them would be fantastic. i've experimented with them, like this, but cant get my head around them.
awk ' { arr[$0]++ } END { for( str in arr ) { if ( arr[str] = 1 ) print str " " arr[str] } } ' /directory/mainfile.txt | >/directory/file1.txt
awk ' { arr[$0]++ } END { for( str in arr ) { if ( arr[str] > 1 ) print str " " arr[str] } } ' /directory/mainfile.txt | >/directory/file2.txt
It's a botch job and not surprisingly doesnt work. even if it did, how do i specify $1 and only $1 as the thing to look at, instead of a string?
Cheers,
Ian:b: