我有一个项目,我可以作其导师。 按开源夏令营,每个项目需要一个宿主单位,这个项目需要一个宿主单位,我挂谁名下呢? 这个项目其实是佟辉老师跟我讨论如何培训学生做一个 1. 确实没人做过的。 2. 确实有需求的。 3. 适合开源/自由软件风格的。 4. 使用基础C语言编程就可以做到的。 5. 很小的项目。 作用是提供学生们一个开源实践的机会,获得长进,同时对开源/自由软件社区确实有所贡献。 设计这样一个项目很困难,因为所有使用基础C语言编程就可以做到的,很小而确实有 需求的项目都有人做过了。 我们共同设计过一段时间,设计出一个题目,原打算让我做导师带佟老师的学生做(那 时候他是一线做教学的),但是这个看起来难度不大的项目,竟然没有学生会做,现在 CSDN的读者圈更大,也许可以出来做。 这样我现在仍然愿意当导师,就跟当时跟佟老师一起工作的一样。 项目需求见本信附件。Title: foldcolumn
Linuxå½ä»¤columnæä¾äº-tåæ°ï¼è¿ä¸ªåæ°å¯ä»¥ä½¿è¡¨æ ¼æ°æ®ï¼å ¸åçæ¯TSVæ°æ®ï¼æ ¼å¼å以便ç¨å¨å±å¹æ¾ç¤ºä¸ãçµåé®ä»¶æ£æä¸åæå°ä¸ã
Linuxå½ä»¤foldæä¾äº-wåæ°ï¼å¯ä»¥ä½¿ææ¬ææå®å宽æ¢è¡ã
column -t
åªç®¡æå¸è¡¨æ ¼ä¸ç®¡æ¢è¡ï¼å®ç°çæææ¯è¾åºç¡ï¼å®é
使ç¨ä¸ï¼è¡¨æ ¼å
çåå
æ ¼ä¹éè¦è½æ¢è¡ãè¿å°±éè¦foldåcolumnå½ä»¤çåè½ç»åèµ·æ¥ãè¿å°±æ¯æ¬é¡¹ç®çéæ±ãå®é
使ç¨ä¸è¿æä¸äºå
¶å®çéæ±ã
è¦æ±å®ç°ä¸ä¸ªç¨åºfoldcolumnï¼å ·æä¸è¿°åè½ï¼
ä¼ ç»column -tè¾åºçè¡å®½æ»æ¯åå³äºæ宽çæ°æ®åï¼æ°¸ä¸åâè¿å®½æ¢è¡âãfoldcolumnéè¦ä¸ä¸ª--width=åæ°ï¼ç®å为-wï¼ï¼æå®è¾åºåªä½ç宽度ãæ¯å¦ï¼foldcolumn -w 80æå®è¾å ¥æ¯è¡80个å符ä½è¿æ ·å®½ï¼ä¸æ¯æ¯è¡80个å符ï¼ãæå®äºå®½åº¦ï¼å¯¹äºå¤ªå®½çæ°æ®åå°±å¿ é¡»æ¢è¡ã举ä¾èè¨ï¼å¯¹äºè¾å ¥ï¼
$ printf "column 1\tcolumn 2\n \è¦å®ç°è¿ä¸ªéæ±ï¼æ两个é¾ç¹ãä¸æ¯å宽çç®æ³ãé«å¢ç¦ <pgf00a gmail com>æåºäºä¸ä¸ªç®åçç®æ³ä»¥ä¾åèï¼
The quick brown fox jumps over a lazy dog. \
The quick brown fox jumps over a lazy dog. \
The quick brown fox jumps over a lazy dog. \
The quick brown fox jumps over a lazy dog. \t \
That's it. Thanks reading.\n" | /usr/loca/bin/foldcolumn -w 80
column 1 column 2
The quick brown fox jumps over a lazy dog. The That's it.
quick brown fox jumps over a lazy dog. The quick Thanks
brown fox jumps over a lazy dog. The quick brown reading.
fox jumps over a lazy dog.
å设ï¼
- å符ç宽
- åè¯å¯ä»¥å¨ä»»æä½ç½®æå¼ï¼è¡¥å è¿å符ï¼
- ä¸å¿ åå精确
- æ¯è¡è³å°å¯ä»¥æ¾ä¸ææå
é£ä¹ï¼
对äºåé¢ç»å®çä¾åï¼å·®ä¸å¤å°±æ¯6æ¯1ã è¡æ°æå°çæ åµæ¯ï¼
- ææææåè¿ç»åï¼ä¸ååçæ åµæ»è¡æ°æå°
- è¦åçå°±æ¯ææææåè¿ç»åï¼ä¸è¿æ¹åä¸ä¸æåç顺åºï¼äº§çååçææ
- æ¯åç宽度为ï¼è¡å®½*ï¼åå符æ°/æ»å符æ°ï¼
- ç®æ³å°±æ¯ï¼å¯¹äºæ¯è¡ï¼å å第ä¸åï¼å°è¾¾ç¬¬ä¸åå宽åï¼å第äºå ...
The quick brown fox jumps over a lazy dog.The quick brown
fox jumps over a lazy dog.The quick brown fox jumps over
a lazy dog.The quick brown fox jumps over a lazy dog. That's
it. Thanks reading.å³ææå 容è¿ç»çè¾åºã
è¦åçå°±æ¯ææææåè¿ç»åï¼ä¸è¿æ¹åä¸ä¸æåç顺åºï¼äº§çååçææã
ä¸ä¾å°±æ¯å°åä½çåï¼ç½åºé»åºçäºç¸äº¤æ¢ä¸ä¸ã
ä¸è¡ä¸è¡çè¾åº
对äºæ¯è¡ï¼
å å第ä¸åï¼å°è¾¾ç¬¬ä¸åå宽åï¼
å第äºåï¼å°è¾¾ç¬¬äºåçå宽åï¼
å第ä¸åï¼
......
å宽çæ¯ä¾ï¼å°±æ¯å符æ°çæ¯ä¾ï¼å 为å设äºå符ç宽ï¼å¦åéè¦è®¡ç®å®é
宽度çæ¯ä¾ï¼è¿ä¸ªæ¹æ³å¯ä»¥æ©å çï¼æ¯å¦åè¯ä¸å¯åçæ¶åï¼å¯ä»¥å¨æè°æ´ï¼ æ¯æ¬¡å¨æè°æ´å¹ 度éæ¸åå°ï¼ç´å°æ¾å°è¾ä¸ºåéçæ åµã æè 计ç®å宽æ¶çåºç©ºæ¡ï¼å 为大家å¾å¾å ³æ³¨çæ¯å·¦è¾¹çç对é½ã
å¼ é¡æ¦ <zhangweiwu realss com> 使ç¨awkè¯è¨å®ç°äºè¿ä¸ªç®æ³ï¼ä»¥ä¾åèï¼
å å¶åä¸ä¸ªæµè¯æ件ï¼
$ printf "The sun went down with practiced bravado. Twilight crawled across the \
sky, laden with foreboding. \tAfter Y2K, the end of the world had \
become a cliché. But who was I to talk, a brooding underdog avenger \
alone against an empire of evil out to right a grave injustice. \
Everything was subjective. There were only personal apocalypses. Nothing \
is a cliché when it is happening to you.\n\
It was a lucky break. The goons inside were spooked, but luck always came \
with a price tag.\tIt was not about how good you were. It was chaos \
and luck and anyone who thought differently was a fool.\n\
Snow fell like ash from post-apocalyptic skies.\t\
Who was I kidding, the best I was, was superman on kryptonite.\n" > /tmp/input.txtåæä¸é¢çèæ¬å为 bin/foldcol.awk
#!/usr/bin/awk -f
# foldcol.awk: perform like fold(1) plus column(1)
# example: foldcol.awk width=72 pass=1 /tmp/input.txt pass=2 /tmp/input.txt
BEGIN { FS="\t"; width=80; } # table default to 80 columns wide
pass==1 {
for (i=1; i<=NF; i++) {
c[i] += length($i); # count of number of chars in each column
t += length($i); # total chars in all columns
}
}
pass==2 {
for (i=1; i<=NF; i++) {
cmd[i] = "echo '" $i "' | " "fold -sw" int(c[i]/t*width)
}
tr = 1 # number of columns that has output of fold(1)
while (tr > 0) { # go on until no column has output from fold(1)
tr = 0
for (i=1; i<=NF; i++) {
l = "";
tr += (cmd[i] | getline l)
printf "[%-" int(c[i]/t*width) "s]", l
}
print "";
}
for (i=1; i<=NF; i++) {
close(cmd[i])
}
}åå¤å¥½èæ¬åæµè¯æ°æ®åï¼æ§è¡ä¸ä¸èæ¬ï¼
$ foldcol.awk width=72 pass=1 /tmp/input.txt pass=2 /tmp/input.txt
[The sun went down with ][After Y2K, the end of the world had become a ]
[practiced bravado. ][cliché. But who was I to talk, a brooding ]
[Twilight crawled across ][underdog avenger alone against an empire of ]
[the sky, laden with ][evil out to right a grave injustice. ]
[foreboding. ][Everything was subjective. There were only ]
[ ][personal apocalypses. Nothing is a cliché ]
[ ][when it is happening to you. ]
[ ][ ]
[It was a lucky break. ][It was not about how good you were. It was ]
[The goons inside were ][chaos and luck and anyone who thought ]
[spooked, but luck ][differently was a fool. ]
[always came with a ][ ]
[price tag. ][ ]
[ ][ ]
[Snow fell like ash from ][Who was I kidding, the best I was, was ]
[post-apocalyptic skies. ][superman on kryptonite. ]
[ ][ ]
ç»å®åæ°-bï¼block-drawingï¼ï¼å¯ä»¥ä½¿ç¨å¶è¡¨ç¬¦ç»è¡¨ã å¶è¡¨ç¬¦æ¯å¦ä¸å¾æ示çæåã
âââ¬â
â ââ
âââ¼â¤
âââ´â
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
6 | â | â | â | â | â¼ | |||||||||||
7 | â | â | ⤠| â´ | ⬠| â |
åºè¯¥è®¸å¯è¾å ¥æ°æ®åå æ ¼é带æ硬å车ã
$ printf "Math\tResult\n 1\r+ 2\r---\r 3\tCorrect\n 1\r- 2\r---\r 1\tIncorrect\n" | foldcolumn -b
ââââââ¬âââââââââââââ
âMathâ Result â
ââââââ¼âââââââââââââ¤
â 1 â Correct â
â+ 2 â â
â--- â â
â 3 â â
ââââââ¼âââââââââââââ¤
â 1 â Incorrect â
â- 2 â â
â--- â â
â 1 â â
ââââââ´âââââââââââââ
å¯ä»¥åç¨æ·æä¾-f <precision>
åæ°ï¼ä»¥ä¾¿èªå¨æ ¼å¼åæ°åãä¾å¦ï¼
$ printf '123.2321825\n125888.4888\n'
123.2321825
125888.4
$ printf '123.2328825\n125888.4\n' | foldcolumn -f 3
123.232
125888.489
注æ-dåæ°éè¦ç¨åºèªå·±å¤æåå æ ¼éæ¯æ°åè¿æ¯å符ï¼å¹¶ä¸æ°åéè¦åå³å¯¹é½ã
æä¾-c <char>
åæ°ï¼åé¢å¯ä»¥å¸¦ä¸ä¸ªå符串ã以æ¤å符串å¼å¤´çè¡ï¼ä¸åå¤çãè¿æäºç±»ä¼¼æ³¨éã
è¾å ¥ï¼
$ printf "Item\tPrice\nComputer\t4000.00\nDesk\t300.00\n* This price table does not include tax.\n" | ./foldcolumn -c '*' -f 2 Item Price Computer 4000.00 Desk 300.00 * This price table does not include tax.
åå ¶å®Linuxå½ä»¤è¡å·¥å ·ä¸æ ·ï¼å¯¹äºæé¿çææ¬åºè¯¥è½ä»åå¦æµãå°¤å ¶æ¯æ°ç¨åºååºè¯¥æ³¨æä¸è¦æææä¸è¥¿é½æ¾å¨ å åéï¼ç¬¬ä¸éåºè¯¥åstrfile(1)è¿æ ·å è¿ä¸ éï¼ç¬¬äºéåè¾åºã