2013-03-04 60 views
-1

用戶從「last」命令中選擇要切割的行以及要切割的列 。除了使用變量之外,使用'tr'到 修復了空白的所有差異。我嘗試了下面的代碼,但不知道我錯在哪裏。使用last和tr切割行和列

echo -n "What rows and columns would you like to cut: " 
read before 
read after 
read stop 
read start 
last | head -n $before friend_list | tail -n $after | tr -d $start $stop 
+0

你期待什麼輸出? – 2013-03-04 23:18:26

+0

來自一組特定行的列表。 – user2133534 2013-03-04 23:38:30

+1

您能給出一個您開始的文本(來自'last')的例子,用戶可能給出的參數以及他們期望的結果嗎? – 2013-03-04 23:45:28

回答

0

聽起來像你要的是這樣的:

last | head -n $after | tail -n $((after-before+1)) | cut -f $start-$stop 

將輸出last的從線$before輸出的子集排隊$after,從$start$stop列。

+0

感謝您的輸入,但是當我嘗試這個時,我得到錯誤「cut:無效字節,字符或字段列表 – user2133534 2013-03-05 00:40:33

+0

@ user2133534:'$ start'和'$ stop'的值是什麼? – ruakh 2013-03-05 00:42:09

+0

共有5列。用戶必須選擇範圍 – user2133534 2013-03-05 00:49:48