Issue
I have a main shell that reformat text from a source to a target file :
Source :
Libelléacte;CHAR(20);Libellé de l'acte;
Target :
* Libellé de l'acte.
05 Libelléacte PIC X(20).
What i want i to remove diacritics only for the first parameter. I tried to convert my file to ascii//TRANSLIT//IGNORE with iconv command but it removes all diacritics and this is not what i want.
This is my reformat code :
for f in $TEMP_DIRECTORY
do
b=$(basename "$f")
echo "Generating $f file in copy..";
awk -F ';' '
toupper($1)=="TABLE" {printf "01 %s.\n\n", $2; next}
toupper($1)=="EXTRACTION" {printf "01 %s.\n\n", $2; next}
{
result = $2
if ($2 ~ /^Numérique [0-9]+(\.[0-9]+)?$/) {
nr=split($2,a,"[ .]")
result = "PIC 9(" a[2] ")"
if (nr == 3) {
result = result ".v9(" a[3] ")"
}
}
sub(/CHAR/,"PIC X", result);
sub(/Char/,"PIC X", result);
sub(/char/,"PIC X", result);
sub(/Entier/,"PIC 9(9)", result);
sub(/entier/,"PIC 9(9)", result);
gsub(/user/,"user-field");
gsub(/User/,"user-field");
gsub("/","_");
printf " * %s.\n\n 05 %s %s.\n\n", $3, $1, result;
}' "$f" > "$TARGET_DIRECTORY/${b%%.*}.cpy"
done
I need to change only the first parameter so i can have this output :
* Libellé de l'acte.
05 Libelleacte PIC X(20).
Solution
First I would use cut
to get the first parameter before the semicolon, then iconv
to transliterate into ASCII, and finally tr
to remove the non-alphanumerics by deleting the [:punct:]
POSIX character class.
cat test | cut -d \; -f 1 | iconv -f UTF-8 -t ASCII//TRANSLIT | tr -d "[:punct:]"
Answered By - Richard Barber Answer Checked By - Senaida (WPSolving Volunteer)