2014-12-01 21 views
0

我有了成千上萬的代碼註釋塊像如何更改與PHPStorm或bash

/** 
* function to do abc 
* and xzy 
* 
* @param ... etc. 

,我想用一團找到替換大寫的第一個字母一個項目代碼註釋的情況下第一行,所以結果是:

/** 
* Function to do abc 
* and xzy 
* 
* @param ... etc. 

是否有可能從PHPstorm中做到這一點? This article建議答案是「否」。如果沒有,我也會歡迎使用bash的命令行解決方案。

+0

接受?這是考試嗎?你自己做了什麼? – 2014-12-01 21:09:56

+0

這不是很好:( – Coleman 2014-12-01 21:19:47

+0

你是否真的嘗試過任何東西?而且這只是一個文本文件?它可能會很容易做到與awk – 2014-12-01 21:32:35

回答

1

你可以嘗試創建一個腳本,然後你位置參數的腳本

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 :)

+0

還請注意,我的代碼是基於你正在寫你的事實代碼模式爲「/ **」和「*」,後跟空格 – repzero 2014-12-02 03:08:57

+0

這是一個很好的問題,你有沒有想過 – repzero 2014-12-02 05:00:40