How to include a variable between apostrophes within a command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to include a variable between apostrophes within a command
# 1  
Old 02-21-2007
How to include a variable between apostrophes within a command

Hi.

I'm trying to find some words within my directory and created a text file containing them which is read by my shell script:
Code:
#!/bin/bash
var=`cat words.txt`
for i in $var; do
	echo $i
        find -type f -print0 | xargs -r0 grep -F '$i'
done

But it searches "$i" (dollar sign with 'i'), and not the word. How to do it?

Thank you very much.
# 2  
Old 02-21-2007
Quote:
Originally Posted by guarriman
Code:
#!/bin/bash
var=`cat words.txt`
for i in $var; do
	echo $i
        find -type f -print0 | xargs -r0 grep -F '$i'
done

Code:
find -type f -print0 | xargs -r0 grep -F "$i"

# 3  
Old 03-16-2007
guarriman,
You can try:
ls -1 | egrep -f words.txt
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mailx command to include sender address

Hi, I m using mailx to send email. I am using sender=server name(display name) echo "body" | mailx -s "subject" -b "bcc address" "to address" -- -f "$sender". I should get email with sender as only display name. In stead i am getting displayname@server address. Please suggest Use code... (1 Reply)
Discussion started by: usrrenny
1 Replies

2. Shell Programming and Scripting

Printing apostrophes by using awk

Hello All, I would like to ask your kind help regarding the following query: I have this line: awk '$2>5 {print "File: "$1,$2}' I have got this output: File: zzzds 76 File: fd9ffh 58 File: gfh0dg 107 .... Could you please help me how to modify my line to get these outputs with... (5 Replies)
Discussion started by: Padavan
5 Replies

3. Shell Programming and Scripting

Find Command Include Sub Directory

This script writes the output files to FILES but I don't want to exclude all directories from ABC_CHQ and LYS_ADV, I want to include one sub directory name process which is under ABC_CHQ and LYS_ADV in the search. Right now its excluding everything from prune directories such as ABC_CHQ, LYS_ADV... (10 Replies)
Discussion started by: John William
10 Replies

4. Shell Programming and Scripting

How to include file pattern in find command?

Hi I've to remove the files which has the following file pattern in path /home/etc/logs fnm_HST_date1 fnm_hst_date1 fnm_HST_date2 I've used the following code to to remove the files having file names like "HST" . #!/usr/bin/ksh set -x file_path=/home/etc/logs file_nm=HST find... (2 Replies)
Discussion started by: smile689
2 Replies

5. UNIX for Dummies Questions & Answers

Problems with deleting punctuation and apostrophes

Dear All, I have a file which I want to get the list of frequency of each word, ignoring list of stop words and now I have problems which punctuations and " 's ". what I am doing is: sed 's///g' file01.txt > file01-clear.txt cat file01-clear.txt | tr "" ""| tr ' ' '\012' |sort |uniq -c... (3 Replies)
Discussion started by: A-V
3 Replies

6. Shell Programming and Scripting

my sed how to include my sftp command!

Hi All, I'm a newbie here, i'm just wondering how can i include my sftp command, here is my code. see below. test -f /home/1.txt && sed -i "s/$/&,pogi" /home/1.txt my sftp command: how can i insert my sftp command in my code above? sftp ${USER}@${HOST} <<-EOF cd ${INPUT_DONE} ... (0 Replies)
Discussion started by: nikki1200
0 Replies

7. Programming

Regex to pull out all words in apostrophes in a string

Hi, I have string like this: CHECK (VALUE::text = ANY (ARRAY)) and I am trying to get out the words in apostrophes ('). In this case"ACTIVE INACTIVE DELETE" Also the array may consist of one or more words (in given example 3). Also instead of word it can be only one LETTER. And... (4 Replies)
Discussion started by: neptun79
4 Replies

8. Shell Programming and Scripting

script to insert variable file into another, bit like C's #include

Hi, I want to insert one file into another like this: file 1: 1 2 3 <!-- #include file="file2" --> 4 5 <!-- #include file="file3" --> 6 with the complete output going to another file. Have seen some solutions to similar problems using sed, but this problem is different because it is... (5 Replies)
Discussion started by: cvq
5 Replies

9. Shell Programming and Scripting

How to include a command in shell script?

# dbc "delete from alert;" DELETE 10 # However, the script created below generates an error that command does not exits. Can any one please exist. script.sh: #!/bin/sh dbc "delete from alert;" >>$TASKLOGFILE ./script.sh: line 38: dbc: command not found can any one please... (2 Replies)
Discussion started by: sureshcisco
2 Replies

10. UNIX for Dummies Questions & Answers

du command to include history

I used du -hk to determine the file sizes on several projects in CVS for a developer i am supporting and he asked me to include history for these projects to get total file size. Was du -hk correct to determine the total size? ---------- Post updated at 09:09 AM ---------- Previous update... (2 Replies)
Discussion started by: Frostywheat
2 Replies
Login or Register to Ask a Question