您可以尝试以下 bash 脚本:
#! /bin/bash
files=(*.java)
for ((i=0; i<=${#files[@]}; i++ )) ; do
file="${files[$i]}"
awk -f r.awk "$file" > "${file}.mod"
done
r.awk
在哪里
{
str=$0
mstr=""
while(match(str,/_([[:alnum:]])/,a)) {
q=substr(str,RSTART+RLENGTH,2)
chr=a[1]
pos=RSTART+RLENGTH
pos2=RSTART-1
if (length(q)==1) {
if (match(q,/[[:alnum:]]/)) {
chr=chr q
pos=pos+1
}
}
else if (length(q)==2) {
if (match(q,/[[:alnum:]][[:blank:]]/)) {
pos=pos+1
chr=chr substr(q,1,1)
}
}
mstr=(mstr substr(str,1,pos2) toupper(chr))
str=substr(str,pos)
}
print (mstr str)
}
给定输入文件file1.java
getEmployee_Name getEmployee_Name
us_employee_id
us_employee_id
asdf_asdf__
我们从awk -f r.awk file1.java
:
getEmployeeName getEmployeeName
usEmployeeID
usEmployeeID
asdfAsdf__