我怎样才能得到;awk“;只修改文件的某些行而不是整个文件?
我想重新使用,以正确使用一些提示表音频文件。这段代码不仅包含所有单词的大写字母,而且遵循一些大写规则,如链接问题中所述 问题是如何修改此代码,使其仅大写“标题”行,而不是整个文件。例如,使用此简单提示表:我怎样才能得到;awk“;只修改文件的某些行而不是整个文件?,awk,Awk,我想重新使用,以正确使用一些提示表音频文件。这段代码不仅包含所有单词的大写字母,而且遵循一些大写规则,如链接问题中所述 问题是如何修改此代码,使其仅大写“标题”行,而不是整个文件。例如,使用此简单提示表: FILE“Two The披头士歌曲.wav”WAVE 轨道01音频 标题“挖一匹小马” 表演者“披头士” 索引01 00:00:00 轨道02音频 标题“从我到你” 表演者“披头士” 索引01 03:58:02 使用简单的for循环加上awk代码,例如: #/垃圾箱/垃圾箱 对于*.cue中
FILE“Two The披头士歌曲.wav”WAVE
轨道01音频
标题“挖一匹小马”
表演者“披头士”
索引01 00:00:00
轨道02音频
标题“从我到你”
表演者“披头士”
索引01 03:58:02
使用简单的for循环加上awk代码,例如:
#/垃圾箱/垃圾箱
对于*.cue中的cue_文件
做
awk'BEGIN{split('a the to at in on with and but or',w);for(i in w)nocap[w[i]}函数cap(word){return toupper(substr(word,1,1))tolower(substr(word,2))}{for(i=1;i请尝试以下内容
awk '
BEGIN{
num=split("a the to at in on with and but or",array," ")
for(i=1;i<=num;i++){
smallLetters[array[i]]
}
}
/TITLE/{
for(i=2;i<=NF;i++){
if(tolower($i) in smallLetters){
$i=tolower(substr($i,1,1)) substr($i,2)
}
else{
if($i~/^\"/){
$i=substr($i,1,1) toupper(substr($i,2,1)) substr($i,3)
}
else{
$i=toupper(substr($i,1,1)) substr($i,2)
}
}
}
}
1
' Input_file
awk'
开始{
num=split(“a to at in on with and but or”,array,”)
对于(i=1;我知道您是否努力理解最初发布的代码,并尝试根据您的用例对其进行修改?是的,我尝试过,但未能成功。我有使用awk.WOW的cero经验!它现在似乎正在工作!请让我在接受它之前再测试一下:)谢谢!
awk ' ##Starting awk program from here.
BEGIN{ ##Starting BEGIN section of this program from here.
num=split("a the to at in on with and but or",array," ") ##Creating array for all words needs to be of lower size.
for(i=1;i<=num;i++){ ##Running a for loop from i=1 to tillvalue of num(length of array).
smallLetters[array[i]] ##Creating an array named smallLetters with index of variable i here.
}
}
/TITLE/{ ##Checking condition if a line contains string TITLE then do following.
for(i=2;i<=NF;i++){ ##Running a for loop from 2nd field to last field of line.
if(tolower($i) in smallLetters){ ##Checking condition if lower case current field is present in array smallLetters.
$i=tolower(substr($i,1,1)) substr($i,2) ##Changing current field to lower case for 1st letter and keeping rest same as it is.
}
else{ ##If current field is NOT in array then do following.
if($i~/^\"/){ ##Checking if field starts from " then do following.
$i=substr($i,1,1) toupper(substr($i,2,1)) substr($i,3) ##Only make 2nd letter Capital since 1st is "
}
else{
$i=toupper(substr($i,1,1)) substr($i,2) ##Else make1st character capital and keep as it is.
}
}
}
}
1 ##Printing edited/non-edited lines here.
' Input_file ##Mentioning Input_file name here.