Here is my source :
TABLE;APGFPOLI;
And here is the output that i want :
01 APGFPOLI.
So what i am trying to do is remove "TABLE" and add 01 before "APGFPOLI". I need to do it for the first line only. So i tried to do :
#!/bin/bash
#Fichier Source
fichier="APGFPOLI.des.txt"
champAdd="05 "
if [[ -f "$fichier" ]]
then
# read it
sed -i '1 s/TABLE//' $fichier |sed -i 's/CHAR/PIC X/' $fichier | sed -E '/Numérique/s/;Numérique\s+([^;]*)/;PIC 9(\1)/' $fichier | while IFS=';' read -r nomChamp format libelle
do
echo \* $libelle
echo $champAdd $nomChamp $format.
done > test.txt
fi
As you can see, my first sed is supposed to remove TABLE but it dont work. i also do a echo for my others line but i'd like to echo this specific first line too.
Here is the output my bash gives me :
*
05 TABLE APGFPOLI.
Here is my full source if it helps :
TABLE;APGFPOLI;
Contrat;CHAR(16);Numéro du contrat
Libelle;CHAR(30);Libellé du contrat
DtCreation;CHAR(8);Date de création
DtMaj;CHAR(8);Date de dernière MAJ
DtEffet;CHAR(8);Date d'effet adhésion
MotifAdh;CHAR(2);Motif d'adhésion
DtRadiation;CHAR(8);Date de radiation
DtEnrRad;CHAR(8);Date enregistrement radiat
MotifRad;CHAR(2);Motif de radiation
MtPrime;Numérique 8.2;Montant prime d'origine
DtEffetSusp;CHAR(8);Date d'effet de suspension
DtFinSusp;CHAR(8);Date de fin de suspension
MotifSusp;CHAR(2);Motif de suspension
DestBord;CHAR(1);Destinataire du bordereau
CdDest;CHAR(5);Code du destinataire
NivRupBord;CHAR(1);Niveau rupture bordereau
BordCETIP;CHAR(1);Bordereau CTIP
EnvBordNom;CHAR(1);Envoi bordereau nominatif
Indice;CHAR(2);Indice appliqué
Echeance;CHAR(2);Echéance de l'indice (MM)
Effectif;CHAR(5);Effectif
CdRegr;CHAR(3);Code regroupement 1
CdGroupe;CHAR(3);Code regroupement 2
Periodicite;CHAR(1);Périodicité
Terme;CHAR(1);Terme
Produit;CHAR(6);Code produit affecté
Inspecteur;CHAR(5);Inspecteur
CleInsp;CHAR(1);Clé inspecteur
Filler;CHAR(6);Filler
-ito the commandsedand to give the name of a file as argument when you are reading the input from the standard input stream with the operator|inbash.sed -idoesn't make any sense in a pipeline. The point of a pipeline is to pass the output from one command to the input of another, butsed -idoesn't produce any output, or read any input. You need to either do the edit with a singlesed -icommand (no pipe, noread, noecho, etc), or make a shell loop over the files (something likefor fichier in *.des.txt; do ...) and usesedwithout the-i(and only pass the file to the firstsedcommand, so the others read from the pipe, not the file).#!/bin/bashto do anything useful, the characters#and!need to be literally the first two bytes of the file. The indentation you show in your question changes this line into just a comment and no longer a valid shebang