I'm trying to find filename with "offending" characters.
All is good except for the caret character. I can't seem to get the regex pattern right.
The error I am getting is as follows:
awk: warning: escape sequence `\^' treated as plain `^'
awk: cmd. line:5: (FILENAME=- FNR=1) fatal: invalid regexp: Unmatched [, [^, [:, [., or [=: /[^]/
/bin/sh code segment is as follows:
for pattern in "[']" '[`]' '["]' '[~]' '[!]' '[&]' '[$]' '[*]' '[?]' '[:]' '[;]' '[%]' '[,]' '[=]' '[@]' '[<]' '[>]' '[#]' '[+]' "[\^]"
do
LC_ALL=C awk -v pat=${pattern} '{
I've tried all the following:
"[\^]"
"[\\^]"
'[^]'
'[\^]'
I've even tried with adding double quotes around the "pat=" assignment, without success. Any ideas what I am doing wrong ?
This is my full script, warts and all:
#!/bin/sh
lookUpChar()
{
awk '{ if( index($0,"|") != 0 ){ print $0 ; } ; }' <"${indxFile}" | sort --version-sort >"BAR_${indxFile}"
{ awk '{ if( index($0,"{") != 0 ){ print $0 ; } ; }' <"${indxFile}"
awk '{ if( index($0,"}") != 0 ){ print $0 ; } ; }' <"${indxFile}"
} | sort --version-sort | uniq >"BRACE_${indxFile}"
{ awk '{ if( index($0,"(") != 0 ){ print $0 ; } ; }' <"${indxFile}"
awk '{ if( index($0,")") != 0 ){ print $0 ; } ; }' <"${indxFile}"
} | sort --version-sort | uniq >"BRK_RND_${indxFile}"
{ awk '{ if( index($0,"[") != 0 ){ print $0 ; } ; }' <"${indxFile}"
awk '{ if( index($0,"]") != 0 ){ print $0 ; } ; }' <"${indxFile}"
} | sort --version-sort | uniq >"BRK_SQ_${indxFile}"
}
cd ${index}
for drv in 2 3 4 5 6 7
do
indxFile="DB001_F${drv}.d.INDEX.txt"
#lookUpChar
### FUTURES: ^
### Not acceptable to awk: '[^]'
for pattern in "[']" '[`]' '["]' '[~]' '[!]' '[&]' '[$]' '[*]' '[?]' '[:]' '[;]' '[%]' '[,]' '[=]' '[@]' '[<]' '[>]' '[#]' '[+]' "[\^]"
do
#awk '{ if( $0 ~ /['\'';:"<>?~,`!@#$*%^&+=]/ ){ print $0 ; } ; }' <"${indxFile}" | sort --version-sort >"PUNCT_${indxFile}"
#awk '/['\'';:"<>?~,`!@#$*%^&+=]/ { print $0 ; }' <"${indxFile}" | sort --version-sort >"PUNCT_${indxFile}"
#LC_ALL=C awk -v pats="\`\"&'" '{
LC_ALL=C awk -v pat=${pattern} '{
n=length($0) ;
#for( i=1 ; i < n-1 ; i++ ){
#pat=substr( pats, i, 1 ) ;
if( $0 ~ pat ){
#printf("\t pat[%d] = \"%s\" |%s\n", i, pat, $0 ) | "cat 1>&2" ;
printf("\t pat = \"%s\" |%s\n", pat, $0 ) | "cat 1>&2" ;
printf("%s|%s\n", pat, $0 ) ;
#break ;
} ;
#} ;
}' <"${indxFile}"
#}' <"${indxFile}" | sort --version-sort >"PUNCT_${indxFile}"
done >"PUNCT_${indxFile}"
done | more