我想在bash中按域对文件中的电子邮件地址列表进行排序。
client_secret
我尝试了排序,但它仅以用户名开头进行排序。
$ cat file.txt
abc@abc.net
bbb@aaa.org
aba@aaa.com
aaa@aaa.com
ccc@abb.com
aba@abb.com
abc@abc.com
我想先对域名进行排序,然后对用户名进行排序。
答案 0 :(得分:2)
int main(){
int **mat1,**mat2,**result;
int row1,col1,row2,col2;
int i,j,k;
FILE *file;
char fname[100];
printf("enter file name\n");
scanf("%s", &fname);
file=fopen(fname, "r");
fscanf(file, "%d %d", &row1,&col1);//row of first matrix
mat1=malloc(row1 * col1 * sizeof(int*));//create memory for first matrix
//reading data for first matrix
for(i=0; i<row1; i++)
{
for(j=0; j<col1; j++)
{
fscanf(file, "%d", &mat1[i][j]);
}
}
for(i=0; i<row1; i++)
{
for(j=0; j<col1; j++)
{
printf("%d\t",mat1[i][j]);
}
printf("\n");
}
fscanf(file,"%d %d", &row2, &col2);//row of second matrix
mat2=malloc(row2 * col2 * sizeof(int*));//create memory for second matrix
//reading data for second matrix
for(i=0; i<row2; i++)
{
for(j=0; j<col2; j++)
{
fscanf(file,"%d",&mat2[i][j]);
}
}
for(i=0; i<row2; i++) //check mat2
{
for(j=0; j<col2; j++)
{
printf("%d\t",mat2[i][j]);
}
printf("\n");
$ sort -t @ -k2 file
aaa@aaa.com
aba@aaa.com
bbb@aaa.org
aba@abb.com
ccc@abb.com
abc@abc.com
abc@abc.net
:
man sort