how to search for string that includes folder separator ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to search for string that includes folder separator ?
# 8  
Old 05-26-2010
Quote:
Originally Posted by pseudocoder
Useless use of cat
I know that some folks tend to consider "making things explicit thus hopefully more transparent" as being useless Smilie
# 9  
Old 05-26-2010
How can I replace hardcoded strings with variables in grep -E ?

Code:
str1='userA'
str2='aaaaaaa'

/usr/xpg4/bin/grep -E '${str1}.*${str2}/+' input.txt

grep: RE error in ${str1}.*${str2}/+ syntax error

# 10  
Old 05-26-2010
Try (double quotes, without curly brackets)
Code:
/usr/xpg4/bin/grep -E "$str1.*$str2/+" input.txt

# 11  
Old 05-26-2010
Quote:
Originally Posted by kchinnam
What does that + do at the end ?
It matches one or more copies of the previous element. Type man grep for further info.

Quote:
I know that some folks tend to consider "making things explicit thus hopefully more transparent" as being useless
...at the cost of an additional process. Smilie
# 12  
Old 05-26-2010
Parameters within regex expression is not working ..Smilie

Code:
> cat input.txt
/userA/bla/bla/bla/../aaaaaaabbb/jakarta
/userA//bla/bla/../../aaaaaaa/jakarta
/userB/bla/../aaaaaaabbb/jakarta
/userB/bla/aaaaaaa/jakarta

$>str1='userA'; str2='aaaaaaa/'; /usr/xpg4/bin/grep -E '$str1.*$str2' input.txt
grep: RE error in $str1.*$str2 unknown regex error

# 13  
Old 05-26-2010
Please also try using double quotes, like I suggested in posting # 10
Code:
/usr/xpg4/bin/grep -E "$str1.*$str2" input.txt

This User Gave Thanks to pseudocoder For This Post:
# 14  
Old 05-26-2010
Thanks for the patience.. Now I got the solution..
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

Use string as Record separator in awk

Hello to all, Please some help on this. I have the file in format as below. How can I set the record separator as the string below in red "No. Time Source Destination Protocol Length Info" I've tried code below but it doesn't seem to... (6 Replies)
Discussion started by: cgkmal
6 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

Need a separator string between fields in cut -c command

Hi All, I'm trying to view data using cut command for a fixed length file using the below command: cut -c 1-3,4-5 FALCON_PIS_00000000.dat I want to mention a separator say | (pipe) in between 1-3 and 4-5. Please let me know how to achieve this. Thanks in Advance, (3 Replies)
Discussion started by: HemaV
3 Replies

5. 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

6. Shell Programming and Scripting

grep regex, match exact string which includes "/" anywhere on line.

I have a file that contains the 2 following lines (from /proc/mounts) /dev/sdc1 /mnt/backup2 xfs rw,relatime,attr2,noquota 0 0 /dev/sdb1 /mnt/backup xfs rw,relatime,attr2,noquota 0 0 I need to match the string in the second column exactly so that only one result is returned, e.g. > grep... (2 Replies)
Discussion started by: jelloir
2 Replies

7. Shell Programming and Scripting

awk, string as record separator, transposing rows into columns

I'm working on a different stage of a project that someone helped me address elsewhere in these threads. The .docs I'm cycling through look roughly like this: 1 of 26 DOCUMENTS Copyright 2010 The Age Company Limited All Rights Reserved The Age (Melbourne, Australia) November 27, 2010... (9 Replies)
Discussion started by: spindoctor
9 Replies

8. UNIX for Dummies Questions & Answers

Sed - Get Separator From String

Hi All, I have the following data in a korn shell variable: a="FirstValue|SecondValue|ThirdValue" The value between "FirstValue", "SecondValue" and "ThirdValue" can change, in this case is a comma: "," and I need to print it only once. I need to know what is the separator value. I... (3 Replies)
Discussion started by: felipe.vinturin
3 Replies

9. Shell Programming and Scripting

passing string which includes metacharacters

I'm trying to create a bash script that takes a URL as one of its arguments like this: ./script.sh http://url.cfm?asdf&asdf=234 variable=$1 echo $variable I'm having trouble storing the URL because it contains the meta character "&" which is being interpreted... thus when I run the... (4 Replies)
Discussion started by: kds1398
4 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