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 ?
# 1  
Old 05-26-2010
how to search for string that includes folder separator ?

I want to select only second line.
I want to search for any line that has both -> [ 'userA' AND 'aaaaaaa/' ]

Code:
 
input.txt
/userA/aaaaaaabbb/jakarta
/userA/aaaaaaa/jakarta
/userB/aaaaaaabbb/jakarta
/userB/aaaaaaa/jakarta


This command does have effect of --> [ 'userA' OR 'aaaaaaa/' ]
Code:
 
$>cat input.txt | /usr/xpg4/bin/grep -E 'userA|aaaaaaa/'
/userA/aaaaaaabbb/jakarta
/userA/aaaaaaa/jakarta
/userB/aaaaaaa/jakarta


I know I can do it by executing grep two times, with piping..
Code:
 
$> cat input.txt | grep 'userA' | grep 'aaaaaaa/'
/userA/aaaaaaa/jakarta


But I am looking for a way to do this in one command,, simplest possible way..!?
# 2  
Old 05-26-2010
Like this?

Code:
grep 'userA\/aaaaaaa\/' input.txt

# 3  
Old 05-26-2010
What's wrong with

Code:
cat in.file | grep -E '/userA/aaaaaaa/'

Smilie
# 4  
Old 05-26-2010
Dr.House,Verdipollo

Yes both of your commands work with initial input.txt file,, Please check the new input.txt file that more accurately reflects my requirement..

My search strings can be seperated by any number of other strings..Sorry for the confusion..

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


I want all the lines that have both string "userA" AND "aaaaaaa/". which may be seperated by any number of other strings.

Last edited by kchinnam; 05-26-2010 at 12:19 PM.. Reason: typo
# 5  
Old 05-26-2010
Like this?

Code:
grep -E 'userA.*aaaaaaa/+' input.txt

# 6  
Old 05-26-2010
Code:
this works
grep -E 'userA.*aaaaaaa/+' input.txt

What does that + do at the end ?
# 7  
Old 05-26-2010
Quote:
Originally Posted by dr.house
What's wrong with

Code:
cat in.file | grep -E '/userA/aaaaaaa/'

Smilie
Useless use of cat Smilie Smilie

kchinnam, this is somewhat like a 1:1 sed translation of verdepollo's grep command, but without that "+" sign.
Code:
sed '/userA.*aaaaaaa\//!d' input.txt

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