将排除数组添加到现有awk代码
鉴于:将排除数组添加到现有awk代码,awk,Awk,鉴于: awk' 开始{ num=split(“a to at in on with and but or”,array,”) 对于(i=1;i编辑:OP TENDED,可能也有类似于“a”的词,所以现在添加以下内容来处理该情况 awk ' BEGIN{ s1="\"" num=split("McCartney feat. vs. CD USA NYC",array," ") for(k=1;k<=num;k++){ temp=tolower(array[k])
awk'
开始{
num=split(“a to at in on with and but or”,array,”)
对于(i=1;i编辑:OP TENDED,可能也有类似于“a”
的词,所以现在添加以下内容来处理该情况
awk '
BEGIN{
s1="\""
num=split("McCartney feat. vs. CD USA NYC",array," ")
for(k=1;k<=num;k++){
temp=tolower(array[k])
ignoreLetters[temp]=array[k]
}
num=split("a the to at in on with and but or",array," ")
for(i=1;i<=num;i++){
smallLetters[array[i]]=array[i]
}
}
/TITLE/{
for(i=2;i<=NF;i++){
front=end=nothing=both=""
if($i~/^"/ && $i!~/"$/){
temp=tolower(substr($i,2))
front=1
}
else if($i ~ /^".*"$/){
temp=tolower(substr($i,2,length($i)-2))
both=1
}
else if($i ~/"$/ && $i!~/^"/){
temp=tolower(substr($i,1,length($i)-1))
end=1
}
else{
temp=tolower($i)
nothing=1
}
if(temp in ignoreLetters){
if(front){
$i=s1 ignoreLetters[temp]
}
else if(end){
$i=ignoreLetters[temp] s1
}
else if(both){
$i=s1 ignoreLetters[temp] s1
}
else if(nothing){
$i=ignoreLetters[temp]
}
}
else if(temp in smallLetters){
if(front){
$i=s1 smallLetters[temp]
}
else if(end){
$i=smallLetters[temp] s1
}
else if(nothing){
$i=smallLetters[temp]
}
else if(both){
$i=s1 smallLetters[temp] s1
}
}
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
代码负责什么:
- 它负责将提到的单词转换成小写字母
- 它负责按照OP提到的风格制作一些信件
- 它获取不属于上述任何类别的其余字段,并将它们的第一个字母作为大写字母
- 代码还负责以
“
开头或以”
结尾的单词,它将首先删除它们以检查它们是否存在于用户提到的数组中,然后根据它们的位置添加它们
很抱歉,这不清楚,请务必让我们知道您不想更改为小写字母的单词,请添加更多详细信息,然后让我们知道。请为您希望保留在文件中的单词添加更清楚的示例。抱歉@RavinderSingh13,可能现在更清楚了可以参考以前的一些单词estion,以防有人想阅读它以获取更多信息,但请确保您发布的每个问题都是独立的,包括它自己的简明文本示例输入、预期输出以及您迄今为止尝试过的代码。请参阅。还要确保所有相关信息都包含在您的问题中,而不是分散在下面的注释中你的问题。是的,埃德·莫顿,你是对的。我对它进行了编辑,对上一个问题进行了更多的参考和解释。评论不是为了扩大讨论;这段对话是。
FILE "Two The Beatles Songs.wav" WAVE
TRACK 01 AUDIO
TITLE "Dig a Pony, feat. Paul McCartney"
PERFORMER "The Beatles"
INDEX 01 00:00:00
TRACK 02 AUDIO
TITLE "From Me to You"
PERFORMER "The Beatles"
INDEX 01 03:58:02
FILE "Two The Beatles Songs.wav" WAVE
TRACK 01 AUDIO
TITLE "Dig a Pony, Feat. Paul Mccartney"
PERFORMER "The Beatles"
INDEX 01 00:00:00
TRACK 02 AUDIO
TITLE "From Me to You"
PERFORMER "The Beatles"
INDEX 01 03:58:02
awk '
BEGIN{
s1="\""
num=split("McCartney feat. vs. CD USA NYC",array," ")
for(k=1;k<=num;k++){
temp=tolower(array[k])
ignoreLetters[temp]=array[k]
}
num=split("a the to at in on with and but or",array," ")
for(i=1;i<=num;i++){
smallLetters[array[i]]=array[i]
}
}
/TITLE/{
for(i=2;i<=NF;i++){
front=end=nothing=both=""
if($i~/^"/ && $i!~/"$/){
temp=tolower(substr($i,2))
front=1
}
else if($i ~ /^".*"$/){
temp=tolower(substr($i,2,length($i)-2))
both=1
}
else if($i ~/"$/ && $i!~/^"/){
temp=tolower(substr($i,1,length($i)-1))
end=1
}
else{
temp=tolower($i)
nothing=1
}
if(temp in ignoreLetters){
if(front){
$i=s1 ignoreLetters[temp]
}
else if(end){
$i=ignoreLetters[temp] s1
}
else if(both){
$i=s1 ignoreLetters[temp] s1
}
else if(nothing){
$i=ignoreLetters[temp]
}
}
else if(temp in smallLetters){
if(front){
$i=s1 smallLetters[temp]
}
else if(end){
$i=smallLetters[temp] s1
}
else if(nothing){
$i=smallLetters[temp]
}
else if(both){
$i=s1 smallLetters[temp] s1
}
}
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 '
BEGIN{
s1="\""
num=split("McCartney feat. vs. CD USA NYC",array," ")
for(k=1;k<=num;k++){
temp=tolower(array[k])
ignoreLetters[temp]=array[k]
}
num=split("a the to at in on with and but or",array," ")
for(i=1;i<=num;i++){
smallLetters[array[i]]=array[i]
}
}
/TITLE/{
for(i=2;i<=NF;i++){
front=end=nothing=""
if($i~/^"/){
temp=tolower(substr($i,2))
front=1
}
else if($i ~/"$/){
temp=tolower(substr($i,1,length($i)-1))
end=1
}
else{
temp=tolower($i)
nothing=1
}
if(temp in ignoreLetters){
if(front){
$i=s1 ignoreLetters[temp]
}
else if(end){
$i=ignoreLetters[temp] s1
}
else if(nothing){
$i=ignoreLetters[temp]
}
}
else 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
FILE "Two The Beatles Songs.wav" WAVE
TRACK 01 AUDIO
TITLE "Dig a Pony, feat. Paul McCartney"
PERFORMER "The Beatles"
INDEX 01 00:00:00
TRACK 02 AUDIO
TITLE "From Me to You"
PERFORMER "The Beatles"
INDEX 01 03:58:02