0
A
回答
1
加倍任何行第二列不包含任何字母的內容可能看起來有點像在本地的bash以下幾點:
#!/bin/bash
# iterate over lines in input file
while IFS= read -r line; do
if [[ $line = *[[:alpha:]]* ]]; then
# line contains letters; emit unmodified
printf '%s\n' "$line"
else
# break into a variable for the first word, one for the second, one for the rest
read -r first second rest <<<"$line"
if [[ $second ]]; then
# we extracted a second word: emit it, doubled, between the first word and the rest
printf '%s\n' "$first $((second * 2)) $rest"
else
# no second word: just emit the whole line unmodified
printf '%s\n' "$line"
fi
fi
done
這從標準輸入讀取和寫入到stdout,所以使用的東西像:
./yourscript <infile >outfile
0
感謝所有,這是我使用本網站第二次,我發現這是非常實用,它可以得到答案很快
我人所以在下面找到
#!/bin/bash
FILE=$1
while read f1 f2 ;do
if[[$f1 != *[!0-9]*]];then
f2=`echo "$f2 -1"|bc` ;
echo "$f1 $f2"
else
echo "$f1 $f2"
fi
做<%FILE一個答案
+0
正如在這裏給出的,這個答案不起作用 - 也許你在輸入表單時忽略了一些空格? –
+1
還有其他的錯誤,比如在輸出中輸出'$ 2'而不是'$ f2',並且如果你想要的值都是整數,那麼在shell中使用內置數學,而不是' bc':'f2 = $((f2-1))' –
相關問題
- 1. 熊貓忽略非數值
- 2. 從Excel導入 - 忽略非數字值
- 3. 運行忽略參數-Dhttp.address = ****
- 4. parseInt()/ parseFloat()忽略非數字參數
- 5. (Lua)使用非數字值進行數學運算
- 6. 如何使to_number忽略非數值
- 7. 在Perl中對非常大的數字執行數學運算
- 8. PostgreSQL文本數組 - 查詢爲整數,忽略非數字
- 9. MySQL的比較字符串忽略非字母數字字符
- 10. 在運行時忽略ngIF假值
- 11. C++ cin數字忽略第一行?
- 12. SQL Server 2008 select語句忽略非字母數字字符
- 13. 如何忽略SQL LIKE語句的非字母數字字符?
- 14. jQuery UI自動完成忽略非字母數字字母
- 15. 忽略可選參數值
- 16. 如何忽略數字
- 17. 忽略小的話,字數
- 18. 數學函數的非數字參數
- 19. ScheduledExecutorService的 - 忽略已運行可運行
- 20. 運行JUnit @Test忽略@前/ @
- 21. 貨物運行忽略
- 22. 對屬性值執行數學運算
- 23. 忽略參數
- 24. 聚合時忽略非空值
- 25. 如何忽略非浮點值
- 26. 角度指令忽略非數字輸入
- 27. Excel:如何忽略圖表中的非數字單元格
- 28. MySQL小數忽略邏輯運算符
- 29. CharacterData忽略非轉義字符
- 30. 帶小數值的EditText值用於執行數學運算
請確認您想_pure Bash_解決方案 - 而不是調用標準的Unix工具,如'從猛砸awk'。 – mklement0
可以說,給出一個答案http://stackoverflow.com/questions/806906/how-do-i-test-if-a-variable-is-a-number-in-bash/806923#806923這變得微不足道。 –