題目描述

顯示每行輸入的第13個字元後的所有字元。



原題網址

輸入格式

輸入一個有著N行ASCII字元的文字檔案。N的範圍在1~100之間(包括1和100)。

輸出格式

將輸入的N行文字中的第13個字元後的所有字元(包括第13個字元),輸出成新的N行。

範例輸入

New York is a state in the Northeastern and Mid-Atlantic regions of the United States.
New York is the 27th-most extensive, the third-most populous populated of the 50 United States.
New York is bordered by New Jersey and Pennsylvania to the south.
About one third of all the battles of the Revolutionary War took place in New York.
Henry Hudson's 1609 voyage marked the beginning of European involvement with the area.

範例輸出

a state in the Northeastern and Mid-Atlantic regions of the United States.
the 27th-most extensive, the third-most populous populated of the 50 United States.
bordered by New Jersey and Pennsylvania to the south.
ird of all the battles of the Revolutionary War took place in New York.
's 1609 voyage marked the beginning of European involvement with the area.

解題概念

利用while和「read」指令,來一行一行讀取從標準輸入傳進來的檔案內容。每讀取到一行資料,就儲存到變數C之中,再作為輸入傳給「cut」指令來進行字串處理。「cut」指令的「-c」選項可以顯示指定位置(column)的字元,如果要指定一段範圍內的字元,可以使用減號「-」來區隔起始位置和終止位置。不過由於這題的終止位置是到該行的結尾,因此要省略終止位置。

參考答案

#!/bin/bash

while read C; do
   cut -c13- <<< ${C}
done