好吧,這是我來到:
1)生成的輸入進行測試
for x in {1..35},aa,bb ; do echo $x ; done > file.csv
for x in {21..48},aa,bb ; do echo $x ; done >> file.csv
for x in {32..63},aa,bb ; do echo $x ; done >> file.csv
unsort file.csv > new.txt ; mv new.txt file.csv
2)你行(更正的語法錯誤)
dtpwmbp:~ pwadas$ for i in $(cut -d "," -f1 file.csv | uniq);
do var=`grep -c $i file.csv`; if [ "$var" -ge 1 ] ;
then echo " you have the following repeated numbers" $i ; fi ; done | head -n 10
you have the following repeated numbers 8
you have the following repeated numbers 41
you have the following repeated numbers 18
you have the following repeated numbers 34
you have the following repeated numbers 3
you have the following repeated numbers 53
you have the following repeated numbers 32
you have the following repeated numbers 33
you have the following repeated numbers 19
you have the following repeated numbers 7
dtpwmbp:~ pwadas$
3)我行:
dtpwmbp:~ pwadas$ echo "you have the following repeated numbers:";
for i in $(cut -d "," -f1 file.csv | uniq); do var=`grep -c $i file.csv`;
if [ "$var" -ge 1 ] ; then echo $i ; fi ; done | head -n 10
you have the following repeated numbers:
8
41
18
34
3
53
32
33
19
7
dtpwmbp:〜pwadas $
我加了引號,改變,如果()以[..]的表達,終於感動描述語句退出循環。測試的發生次數在「-ge」狀態附近是數字。如果是「1」,則打印出現一次或多次的數字。注意,在這個表達式中,如果文件包含例如數字
然後 「8」 輸出被列爲出現兩次。使用「-ge 2」時,如果沒有數字出現超過一次,則不會輸出(標題除外)。
試圖在for循環之前移動標題行的回顯? – svante
但是在這種情況下,如果沒有重複的數字,那麼它就沒有意義了 – t28292
如果你可以建議另一個命令,因爲我面臨這個問題:如果455在輸入的第2,3和15行重複文件,它會顯示兩次,如455 879 741 455(肯定是列形式) – t28292