나는 speficially 약간의 조정을 필요로 .SQL 파일을 가지고유닉스
[Blah]
즉 xx_prefix와 대문자를 다음 문자를 제거하십시오.
팁이 있습니까?
나는 speficially 약간의 조정을 필요로 .SQL 파일을 가지고유닉스
[Blah]
즉 xx_prefix와 대문자를 다음 문자를 제거하십시오.
팁이 있습니까?
간단한 blah
교체 :
$ sed -e 's/\[[^]]*_blah]/[Blah]/g' old.sql > new.sql
보다 일반적인 : 오히려 .+
보다 [^]_]+
와 접두사와 일치하는
$ perl -pe 's/\[[^]_]+_(.+?)]/[\u$1]/g' old.sql > new.sql
이유는 정규 표현식 수량 자 욕심이다. 예를 들어, 후자는 입력으로 [xx_blah][xx_blah]
이 가능한 한 많이 중얼 거려서 의도 한 것이 아닌 xx_blah][xx
과 일치합니다. 오른쪽 괄호와 밑줄을 제외하면 안전 정지가됩니다.
대체품의 \u
은 다음 문자를 대문자로 사용하는 escape sequence입니다. 당신이 나오지 선호와 눈이 모두 백 슬래시에서 교차되지 않는 경우
, 당신은 단지 외부 도구
#!/bin/bash
declare -a arr
while read -r -a arr
do
for((i=0;i<=${#arr};i++))
do
case "${arr[i]}" in
*"[xx_"*);;&
*"["*)
arr[i]=${arr[i]//xx_/}
arr[i]=${arr[i]^^${arr[i]:1:1}}
esac
done
echo ${arr[@]}
done < "file"
예를하지 않고 쉘을 사용할 수 있습니다
$ sed -e 's/\[[^]_]\+_\(.\+\?\)]/[\u\1]/g' old.sql > new.sql
로 이동 실행시 출력량
PS1> more file
this is first line
this is second line
[xx_blah]
this is fourth line
blah [xx_blah] blah [xx_blah]
[someText]
end
PS1> ./mychanger.sh
this is first line
this is second line
[Blah]
this is fourth line
blah [Blah] blah [Blah]
[SomeText]
end
해당 사항 없음 e는 작동하는 것처럼 보였습니까? 파일이 Windows 컴퓨터에서 작성 되었기 때문에 그럴 수 있습니까? (간격 탭? 개행?) – mrblah
'diff -ub old.sql new.sql'의 출력이 비어 있었습니까? –