Remova todos os caracteres após caracteres não ASCII em todas as colunas

Remova todos os caracteres após caracteres não ASCII em todas as colunas

Eu tenho um script bash que removerá todos os caracteres não Ascii do arquivo. Mas eu queria remover a string após o caractere não Ascii em todas as colunas. Abaixo está o roteiro,

> #!/bin/bash

SCRIPT_PATH=/trmout/TRMOUTPUT_PROD
BKP_PATH=/appinfprd/bi/infogix/Temp_Files/SUPPLY_CHAIN

File_Name=WB


########################################################################
##Deleting the precessed files ####
########################################################################

cd $BKP_PATH
rm *.*

#########################################################################
### removing the non ascii char from all Supply chain files #######
#########################################################################

for i in $SCRIPT_PATH/$File_Name*.txt
do

cp $i $BKP_PATH

##########################################################################
##Replacing the NON ASCII Char from Supply Chain files and saving it.####
##########################################################################
cat $i  >> $i.bkp

sed -i 's/[\d128-\d255]//g' $i.bkp

mv $i.bkp $i

done


#############################################################################################
##Creating a sample file which will be having the file name which has NON ASCII Char in it.##
#############################################################################################

cd $SCRIPT_PATH

grep -vlP '^[\0-\x7f]*$' WB*.txt >Supply_chain_Non_Ascii_List_File.txt
~
~

Responder1

Você quer dizer que deseja excluir qualquer coisa na linha após o primeiro caractere não-ascii? Caso contrário, forneça alguns exemplos.

Se sim, seu sed deve ser:

sed -i 's/[\d128-\d255].*$//' $i.bkp

Isso substituirá o primeiro caractere não-ascii E o restante da linha por nada.

informação relacionada