answersLogoWhite

0

You have mentioned "Shell Script", I assume you are working on Linux/Unix/Mac OS X environment.

I would suggest to use small utility which by default should be included in almost all above mentioned OS families. It is called sed (stream editor).

Here is how to use the utility:

sed -e 's/#//g' source_file.txt > destination_file.txt

What it does it changes all '#' to '' (removes it).

's///g':

* s - substitute * - standard regular expression * - symbol that will be as replacement. * g - global Here is a Bash Script: #!bin/bash

# Checking parameters number, we need two

if [ $# -ne 2 ]

then

echo "Wrong number of parameters, please try again."

exit 1

fi

# Checking to see if file actuall exists and it is readbale

if [ -e $1 -a -s $1 ]

then

# Calling sed program to find all '#' character and replace them with '' (empty),

# redirecting stdout (standard output stream) to file (second argument)

sed -e 's/#//g' $1 > $2

echo "Job done, please check " $2 " file."

else

echo "Missing file, please try again."

exit 2

fi

exit 0

First parameter of script should be input file and second one - output file.

Source File:

Word # Word

Word #

# Word

Destination File:

Word Word

Word

Word

To change more than one character you could use this regular expression:

s/[Word]/A/g

Same source file and destination would look like:

AAAA # AAAA

AAAA #

# AAAA

[All possible chars]; [Word] = { 'W' OR 'o' OR 'r' OR 'd' }

There are utilities like tr, that could be used for the same purpose.

User Avatar

Wiki User

16y ago

What else can I help you with?