파일에서 모든 비 Ascii 문자를 제거하는 bash 스크립트가 있습니다. 하지만 모든 열에서 Ascii가 아닌 문자 뒤에 있는 문자열을 제거하고 싶었습니다. 아래는 스크립트입니다.
> #!/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
~
~
답변1
첫 번째 비ASCII 문자 뒤의 줄에서 무엇이든 삭제하시겠습니까? 그렇지 않다면 몇 가지 예를 들어주세요.
그렇다면 sed는 다음과 같아야 합니다.
sed -i 's/[\d128-\d255].*$//' $i.bkp
이것은 ASCII가 아닌 첫 번째 문자와 줄의 나머지 부분을 아무것도 대체하지 않습니다.