How to search the files with the value in a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to search the files with the value in a variable
# 8  
Old 11-05-2008
Can someone further help on this?

Hello All,

As explained above, i am also into similar issue Smilie

Brief on the issue (PS:* used below is nothing but space):

If i execute the below command on the command line:
date +'%b %e'
Output is: Nov 5 [Nov**5]

but when i am trying to store this into a variable as below inside a script:

set dt = `date +'%b %e'`
echo "$dt"


and then run the script (.csh)

Output: Nov*5


Required output from the script should be Nov**5


can some one help on this.....

thanks a ton in advance....cheers.
# 9  
Old 11-05-2008
Try set dt="`date +'%b %e'`".
# 10  
Old 11-06-2008
Hiii

date "+%b %e"

The command can be used in any grep statement instead of storing it in a variable ..like the below one

grep "$(date "+%b %e")"Smilie
# 11  
Old 11-06-2008
with the command -> date "+%b %e"
Output: Nov 6

the commands provided in the didnt work Smilie Smilie

ls -ltr | grep 'date "+%b %e"'
ls -ltr | grep '(date "+%b %e")'
ls -ltr | grep '$(date "+%b %e")'

ls -tlr | grep "$(date "+%b %e")"
Error: grep: can't open %e)


but if i execute:
ls -ltr | grep 'Nov 6'

i get the required output.

any other inputs ?
# 12  
Old 11-06-2008
This work for me:
Code:
ls -ltr | grep "$(date '+%b %e')"

..maybe you need:
Code:
ls -ltr | grep "$(date '+%b%e')"

# 13  
Old 11-06-2008
Quote:
Originally Posted by sparks
The command can be used in any grep statement instead of storing it in a variable ..like the below one

grep "$(date "+%b %e")"Smilie
As Ajay discovered, some shells don't cope well with nested double quotes, even though the $( ... ) should have higher precedence, so it's not a safe syntax to use.
# 14  
Old 11-07-2008
The patter in grep must always be enclosed in double quotes.
try that..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk -Search pattern through Variable

Hello, We have wrote shell script for multiple file name search pattern. file format: <numner>_<20180809>.txt starting with single number and ending with 8 digits number Command: awk -v string="12_1234" -v serch="^+_+$" "BEGIN{ if (string ~/serch$/) print string }" If sting matches... (4 Replies)
Discussion started by: koti_rama
4 Replies

2. Shell Programming and Scripting

awk variable search and line count between variable-search pattern

Input: |Running the Rsync|Sun Oct 16 22:48:01 BST 2016 |End of the Rsync|Sun Oct 16 22:49:54 BST 2016 |Running the Rsync|Sun Oct 16 22:54:01 BST 2016 |End of the Rsync|Sun Oct 16 22:55:45 BST 2016 |Running the Rsync|Sun Oct 16 23:00:02 BST 2016 |End of the Rsync|Sun Oct 16 23:01:44 BST 2016... (4 Replies)
Discussion started by: busyboy
4 Replies

3. Shell Programming and Scripting

awk search using variable

Hi Forum. I have the following script that I would like to use a variable to search using awk but it's not working as expected: # Define working variables token_search_string=536088 token_search_length=16 This code example works by hardcoding 536088 in the string search: awk -v... (10 Replies)
Discussion started by: pchang
10 Replies

4. UNIX for Dummies Questions & Answers

Search and replace with variable

Hello all, I stumbled upon a command line for multiple search and replace within given destination perl -pi -w -e 's/SEARCH_FOR/REPLACE_WITH/g;' *.html I want to replace the following line where the date is the variable, from <div class="meta"> <ul> <li>05.05.2015 with date tags, like... (5 Replies)
Discussion started by: uninuub
5 Replies

5. Shell Programming and Scripting

How to search file for a date variable?

Hello, I'm trying to write a ksh script which will allow me to to search for yesterday's date within a rtf file. I just need someway to know if the date is in the file, echo results to a text file, and then mail that out. The format of the date is mm/dd/yyyy. I had to make a variable... (2 Replies)
Discussion started by: ronan1219
2 Replies

6. Shell Programming and Scripting

search replace with loop and variable

Hi, could anyone help me with this, tried several times but still not getting it right or having enough grounding to do it outside of javascript: Using awk or sed or bash: need to go through a text file using a for next loop, replacing substrings in the file that consist of a potentially multi... (3 Replies)
Discussion started by: wind
3 Replies

7. SuSE

Search all files based on first and in all listed files search the second patterns

Hello Linux Masters, I am not a linux expert therefore i need help from linux gurus. Well i have a requirement where i need to search all files based on first patterns and after seraching all files then serach second pattern in all files which i have extracted based on first pattern.... (1 Reply)
Discussion started by: Black-Linux
1 Replies

8. UNIX for Advanced & Expert Users

Search files with specfic extention and later search content

Hi, I would appriciate if somebody can help me figure out how to search for all the *.xml file under a specific directory and subdirectroies (/home/username) and later search of content "<start>" inside the xml file returned by search. -Lovin.V (2 Replies)
Discussion started by: lovi_v
2 Replies

9. Shell Programming and Scripting

Search in variable for character

qwertyuioplkjhgfdsa (1 Reply)
Discussion started by: rorey_breaker
1 Replies

10. Shell Programming and Scripting

search & replace in variable

Can I use search & replace in any variable? Suppose I have one variable named var1 which holds value "abcabc" I need to search 'a' in var1 and want to replace with 'x' like 'xbcxbc'. Is it possible? Can you provide me an example? Malay (3 Replies)
Discussion started by: malaymaru
3 Replies
Login or Register to Ask a Question