在UNIX

时间:2018-04-12 00:14:17

标签: sorting unix ksh

我正在尝试在Unix Korn shell中对文本文件的行进行排序。

示例文件:

3|"Apple"|"iphoneX"|"This is the latest phone."|"California"
2|"Samsung"|"s9"|"This phone isn't so good.
It hangs for no reason when old."|"Texas"
1|"OnePlus"|"5t"|"This is a good android phone."|"Arizona"

预期的O / P:

1|"OnePlus"|"5t"|"This is a good android phone."|"Arizona"
2|"Samsung"|"s9"|"This phone isn't so good.
It hangs for no reason when old."|"Texas"
3|"Apple"|"iphoneX"|"This is the latest phone."|"California"

我试过了:

${FileDir}${INPUT_FILE} |sort -t '|' -k ${SORT_COL_ORD} >>${FileDir}${SORT_OUTPUT_FILE}

但由于第2行有新的换行符,它失败了。我的O / P是这样的:

1|"OnePlus"|"5t"|"This is a good android phone."|"Arizona"
2|"Samsung"|"s9"|"This phone isn't so good.
3|"Apple"|"iphoneX"|"This is the latest phone."|"California"
It hangs for no reason when old."|"Texas"

我正在通过一个arg对第1列(Ids)进行排序。我在这里错过了什么?

0 个答案:

没有答案