bash script help: escaping the '*'


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash script help: escaping the '*'
# 8  
Old 10-07-2005
the problem is detecting that $word is equal to the '*' char
# 9  
Old 10-07-2005
thanks very much Vino Smilie

if i could just detect the '*', i can just not write it out to the output-file
to make matters easier.
# 10  
Old 10-07-2005
'*' character problem

the following code does.....
- accepts a document (text), scans through it word for word,
- finds out if the current word is in the stoplist
- if it exists, ignore word, otherwise write it to a file w/ same
- basename as original file.

Problem: the if [ "$word" = "\*" ]; then block cant recognize a single '*'
that occurs in the document. i want the code to be able to ignore '*'
characters occurring by themselves, i.e. surrounded by whitespaces..

When this code is run with a text file, it completely ignores the test for '*'
chars, and continues to the other if block and echoes '*' to the outfile.
the result of echoing '*' prints all the filenames in the current directory
in the outfile.

something is definitely wrong with testing for the '*'..... help guys! Thanks a bunch! Smilie

Code:
#!/bin/bash

DOC="$1"
STOPLIST="stopwords.list"
BASENAME=`basename $DOC`

# Scan through the document
for word in `cat $DOC`
do

        # skip '*'
        if [ "$word" = "\*" ]; then
                continue
        fi

        # Look-up current word in stop list
        /usr/xpg4/bin/grep -q -w "$word" $STOPLIST

        # if word is not in stoplist, write it
        if [ $? = 1 ]; then
                echo "$word " >> $BASENAME.stop
        fi
done

# 11  
Old 10-07-2005
How about this ?

Code:
#! /bin/sh
# 
while read line
do
        # Test a line which contains only *
        if [[ "$line" == "*" ]] ; then
        echo "Only $line"
        # Test a line containing characters along with a *
        elif [[ "$line" == *"*"* ]] ; then
                echo "Contains * - $line"
        fi ;
done < input.txt

vino
# 12  
Old 10-07-2005
Rules say

(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post where your goal is to get an answer more quickly.


Duplicate post --> bash script help: escaping the '*'

Did you check the solution provided ?

Note: I have merged the threads -- Perderabo

Last edited by Perderabo; 10-07-2005 at 01:54 PM..
# 13  
Old 10-07-2005
sorry. yup i did..unfortunately none of them worked to help the situation..
# 14  
Old 10-07-2005
Even this ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies

2. UNIX for Beginners Questions & Answers

Help with bash escaping while using screen command

Hello, everyone. I'm currently trying to write a command system for a Minecraft server using screen. Here are the scripts I'm currently using. 0.sh #!/bin/bash screen -S Test114 -dm java -Xmx4G -jar server.jar nogui 1.sh #!/bin/bash args="$@" args2="${args@Q}" #args3=`printf '%q\n'... (2 Replies)
Discussion started by: Develon
2 Replies

3. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

4. Shell Programming and Scripting

Bash Vs. Bourne REGEX: metacharacters escaping

I am currently reading a very old reference from O'Reilly: Sed and Awk 2nd Edition reprinted in 2000. So far, it's a solid read and still very relevant. I'd highly recommend this to anyone. The only problem I have with this book is that I had to resort to bourne shell to get my examples to work... (3 Replies)
Discussion started by: ConcealedKnight
3 Replies

5. Shell Programming and Scripting

Wanted: Help with escaping bash command line arguments

Please forgive me if this is the wrong forum. I want to execute some one liners with the groovy programming language and I'm having trouble escaping the special characters to accommodate bash. Here is one of the lines that is giving me trouble: groovy -e "(new... (1 Reply)
Discussion started by: siegfried
1 Replies

6. Shell Programming and Scripting

Escaping problem in a shell script

Hi, i made a gnuplot script which accepts a filename as parameter (using gnuplot -e) now i want to run this script from a shell script, the correct command (with a concrete parameter) looks like this: gnuplot -e 'name="filename.dat;col=2"' gplscript.gpl my shell script looks like this: ... (4 Replies)
Discussion started by: franko007
4 Replies

7. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

8. Shell Programming and Scripting

escaping double-quotes inside the script?

I'm having a strange problem with escaping double-quotes. I have a script that looks like this: #!/bin/bash for HOST in `cat $INFILE | grep -v ^#` do for VFILER in `some_command` do echo " " echo -e '\E The problem with ssh command... (3 Replies)
Discussion started by: GKnight
3 Replies

9. Shell Programming and Scripting

Escaping '*' in Bash

I have the following situation ============ export DirectoryName=/tmp/xyz if ; then some_new_env=$DirectoryName"/*" ======================= I tried all the ways of escaping the '*', but still the shell seems to expand the '*' character. I want some_new_env to contain "/tmp/xyz/*" ... (7 Replies)
Discussion started by: rkshukla14
7 Replies

10. Shell Programming and Scripting

Escaping apostrophe using shell script

Hi, I am using the KSH shell. I am facing a problem of escaping apostrophe('), that is occuring in a variable. I used the following command, but in vain item=`echo $item|sed 's/&apos;/\'/g'` this code replaces the occurance of &apos; in an xml file to apostrophe(') symbol. The output of... (2 Replies)
Discussion started by: mradul_kaushik
2 Replies
Login or Register to Ask a Question