Search a string having spaces


 
Thread Tools Search this Thread
Operating Systems AIX Search a string having spaces
# 1  
Old 06-18-2013
Wrench [Solved] Search a string having spaces

Hi

I am looking to search a string having spaces in a directory


for example :

my string is "summer hot"

my code :
Code:
for i in `cat position__list.txt`
do
        echo $i" : " `find . -mtime -6 | xargs grep -l ":83D:$i" | xargs ls -ltr|tail -1|awk '{ print $6 , $7 , $8, $9; }'`>>/anilkln/outputposition.txt
done

here I am searching ":83D:summer hot"
and when I do this I am getting the list of filenames having "summer" and a separate list of filenames having "hot"

Moderator's Comments:
Mod Comment Code tags for code, please.

Last edited by Corona688; 06-18-2013 at 06:40 PM..
# 2  
Old 06-18-2013
The problem is that xargs by default has a problem with space.
You can escape this with the -i option and {}
Code:
find . -mtime -6 | xargs -i grep -l ":83D:$i" {} | xargs -i ls -ltr {} | tail -1

# 3  
Old 06-19-2013
Tried the same but no luck.It is not working.please advice. I want only the filenames having the string ":83D: summer hot"

Last edited by wedng.bell; 06-19-2013 at 09:48 AM..
# 4  
Old 06-19-2013
Ran on AIX 5.3:

Code:
find /tmp -name '*:83D:*summer*hot*' -type f -print

/tmp/file-:83D: summer hot.txt

# 5  
Old 06-19-2013
This could not help me because the string will come from the input file
# 6  
Old 06-19-2013
Hmm yes, also the rest of your code is not space-safe.
The for loop works with a list, and `cat file` is a quick-and-dirty method to obtain a list. A while loop is more robust. And all references $i should be in quotes.
Code:
while read i
do
  echo "$i : " `find . -mtime -6 | xargs -i grep -l ":83D:$i" {} | xargs -i ls -ltr {} 
| tail -1 | awk '{ print $6 , $7 , $8, $9; }'`
done < position__list.txt >>/anilkln/outputposition.txt

If all output inside the loop is redirected to a file, then it is more efficient to redirect the loop.

Last edited by MadeInGermany; 06-19-2013 at 01:48 PM..
This User Gave Thanks to MadeInGermany For This Post:
# 7  
Old 06-21-2013
Thanks this workedSmilie

Moderator's Comments:
Mod Comment edit by bakunin: changed thread title to "solved".

Last edited by bakunin; 06-23-2013 at 05:19 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. Shell Programming and Scripting

Search for an undetermined number of spaces

I would like to find an undetermined number of spaces and shorten them to one space. I am running Debian in mksh. Script running in #!/bin/sh. Sorry to not include all code. The program is too big and involves an online file... too much hassle to solve a simple issue. Ex., I start with... (11 Replies)
Discussion started by: bedtime
11 Replies

3. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

4. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

5. Shell Programming and Scripting

search pattern that has spaces with nawk

Hi guys, I need a help ! I need do grab some string from file and then count n lines after that pattern. This is working fine, but my problem is that the string to be searched has spaces within, like an example : LINK COUNTERS what I am using is: nawk... (2 Replies)
Discussion started by: robdcb
2 Replies

6. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

7. Shell Programming and Scripting

sed: replace string with another string (with spaces)

Hi I have an XML file with strings XABCD, XEFGHX and XIJKLX. I would like to replace XABCDX with "This is the first string", XEFGHX with "This is the second string" and XIJKLX with "This is the third string". What is the best way to implement this? Should I have a file with the data that is... (4 Replies)
Discussion started by: zmfcat1
4 Replies

8. Shell Programming and Scripting

Search string with invariable spaces

I need to grep for pattern "enable_cal = true".The problem is that different file has different no of spaces in that string. for eg one file will have "enable_cal <space><space><space>=true" next file will have "enable_cal= <space><space>true" other one will have... (5 Replies)
Discussion started by: villain41
5 Replies

9. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies

10. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies
Login or Register to Ask a Question