0

I have a bash script which will remove all the Non Ascii character from the file. But i wanted to remove the string after the non Ascii character in all the columns. Below is the script,

> #!/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
  • post a testable input file fragment Commented Nov 29, 2017 at 8:09

1 Answer 1

0

Do you mean you want to delete anything on the line after the first non-ascii character ? If not, please provides some examples.

If yes, your sed should be :

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

This will replace the first non-ascii character AND the rest of the line with nothing.

1
  • sed -i 's/[\d128-\d255][^|]*|/|/' WB* < $i.bkp This will replace the first non-ascii character till the first Column seperated by |. Commented Dec 5, 2017 at 3:58

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.