你可以嘗試創建一個腳本,然後你位置參數的腳本
my_script.sh <file with the codes to be change > <new file with codes start with upp. case>
假設你的代碼在你的文件是這樣的:
/**
* function to do abc
* and xzy
*
* @param ... etc.
/**
* function to do abc
* and xzy
*
* @param ... etc.
/**
* function to do abc
* and xzy
*
* @param ... etc.
/**
* function to do abc
* and xzy
*
* @param ... etc.
創建文件my_script並添加代碼下面這個文件裏面
#!/bin/bash
###remove any existing file that will have the new codes starting with upper case chars ###
rm -f "$2" 2> /dev/null
##let us set up a while loop that will read the original file that starts with L-case letters####
clue=""
while read -r line; do
if [ "$clue" != "" ]; then
lower_word=`echo "$line"|tr -s [:space:] ' ' |cut -d ' ' -f2`
upper_word=`echo "$line"|tr -s [:space:] ' ' |cut -d ' ' -f2|sed -e "s/\b\(.\)/\u\1/g"`
new_sentence=`echo "$line"|sed "s/$lower_word/$upper_word/g"`
echo "$new_sentence" >> $2
else
echo "$line" >> $2
fi
if [ "$line" = "/**" ]; then
clue="/**"
else
clue=""
fi
done < $1
現在運行腳本..你的輸出文件應該有:
/**
* Function to do abc
* and xzy
*
* @param ... etc.
/**
* Function to do abc
* and xzy
*
* @param ... etc.
/**
* Function to do abc
* and xzy
*
* @param ... etc.
/**
* Function to do abc
* and xzy
*
我刪除我的答案是第一次,因爲我從第一inception.My道歉誤解了你的問題道歉,我不是在bash壓痕的忠實粉絲喜歡我在python :)
接受?這是考試嗎?你自己做了什麼? – 2014-12-01 21:09:56
這不是很好:( – Coleman 2014-12-01 21:19:47
你是否真的嘗試過任何東西?而且這只是一個文本文件?它可能會很容易做到與awk – 2014-12-01 21:32:35