Using grep to find one or more characters


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using grep to find one or more characters
# 1  
Old 02-09-2009
Using grep to find one or more characters

Hi

I am a little stuck using grep. I want to be able to find from a file all lines which have the sequence of characters t, followed by any character, followed by the characters ing.

I have tried looking at the man pages for help, but did not understand it correctly (as it is not the most helpful manual)

Thank you if you can help. Also if you have a tutorial on grep would you give me a link to it please.

Thanks.
# 2  
Old 02-09-2009
Hammer & Screwdriver

Code:
>grep "t[a-z]ing" myfile

# 3  
Old 02-09-2009
Thanks, and would

Code:
grep '[thing][talking][tring][ting]

find in a file the things above?

Thanks if you can help.
# 4  
Old 02-09-2009
This isn't the most efficient way to do it, but it will force the First character in the line to be "t", and the last three characters do be "ing".
Code:
grep ^t /path_to_file/file | grep ing$

# 5  
Old 02-09-2009
I'm not sure if it answered my second question, but is the method below the way to find from a file all lins which contain the sequence of characters thing, talking, tring and ting?

Code:
grep '[thing][talking][tring][ting]'

# 6  
Old 02-09-2009
Quote:
Originally Posted by rushhour
Thanks, and would

Code:
grep '[thing][talking][tring][ting]

find in a file the things above?

Thanks if you can help.
Code:
grep 't.*ing'

Use a dot to match any single character, except a newline:

Code:
grep 't.ing'

A useful tutorial to understand regular expressions:

Regular Expressions

Regards
# 7  
Old 02-09-2009
Quote:
Originally Posted by Franklin52
Code:
grep 't.*ing'

Use a dot to match any single character, except a newline:

Code:
grep 't.ing'

A useful tutorial to understand regular expressions:

Regular Expressions

Regards
So you are saying to find thing, talking, tring and ting, withing a file, I should use the following:

Code:
grep 't.ing' myFile

kind of confusing, it doesn't seem like this is the answer!
Any help would be great if you can explain it.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep with ... matching more than 3 characters

I am trying to understand what the grep command in ubuntu is trying to do here. The contents of my test file is given below harsha@harsha-H67MA-USB3-B3:~/Documents$ cat data abcd efghi jklmno pqr stuv wxyz When I grep for 3 dots (...) without the parenthesis as follows I would expect the... (4 Replies)
Discussion started by: sreeharshasn
4 Replies

2. Shell Programming and Scripting

grep particular characters help

Hello folks i have file which is below, i want to extract last column of file that contains dm-21 or dm-13 or dm-N it show output like I have tried but i got this (16 Replies)
Discussion started by: learnbash
16 Replies

3. Shell Programming and Scripting

Grep with special Characters

Need Help For GREP I have a file say g1.txt and content of file is below REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoDrives /t REG_DWORD /d 4 /f , REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoClose /t REG_DWORD /d 1 /f ,... (4 Replies)
Discussion started by: jalpasoni
4 Replies

4. UNIX for Dummies Questions & Answers

Is it possible to grep a certain amount of characters?

I have a file similar to the following filler filler filler car 6 mazda filler filler filler filler car civic honda car rav 4 toyota filler filler If i do a "grep -i car file.txt" the output would be car 6 mazda car civic honda car rav 4 toyota however, i want to have the... (4 Replies)
Discussion started by: jl487
4 Replies

5. Shell Programming and Scripting

Grab characters following grep

Hi all, I'm trying to gather data directly following a keyword in a file but I have no guarantee where it will appear in said file so I can't use cut or anything else that assumes it will be located at a certain position. If anyone has any suggestions I'd be grateful. Here is an example of the... (7 Replies)
Discussion started by: Korn0474
7 Replies

6. UNIX for Dummies Questions & Answers

Using GREP for special characters

Hi folks I am issuing the following command: grep "" * Looking for the characters \/:*?"<>|#+%& within all files in a directory, but the command fails being unhappy with pipe: ksh: 0403-057 Syntax error: `|' is not expected. How do I force the command to take the pipe | ? I guess... (2 Replies)
Discussion started by: daveaasmith
2 Replies

7. Shell Programming and Scripting

grep non printable characters

Sometimes obvious things... are not so obvious. I always thought that it was possible to grep non printable characters but not with my GNU grep (5.2.1) version. printf "Hello\tWorld" | grep -l '\t' printf "Hello\tWorld" | grep -l '\x09' printf "Hello\tWorld" | grep -l '\x{09}' None of them... (3 Replies)
Discussion started by: ripat
3 Replies

8. UNIX Desktop Questions & Answers

grep with special characters

Hi there I need to grep for a detail from a file. The pattern to search for involves escape sequences in it. This causes for the problem. grep "P\_SOME\_STRING\_SEARCH" filename Note, I have line like below in the file and expect it to grep. select * from my_system_param ... (3 Replies)
Discussion started by: guruparan18
3 Replies

9. Shell Programming and Scripting

Grep with Special Characters

I need to sort a file, the sort is not a alphabetical sort, it's based on a predefined order which is read from a file called fSortOrder. The format of the fSortOrder file is : STARTPATH" .... .... The file that needs to be sorted is called tmpUnsorted and contains data in the format : ... (6 Replies)
Discussion started by: Vashj
6 Replies

10. UNIX for Dummies Questions & Answers

Grep and extract the characters after

Hi All, I have lines like below in a file A /u/ab/test1.dat A/u/ab/test2.dat A /u/bb/test3.dat A/u/cc/test4.dat I will need /u/ab/test1.dat /u/ab/test2.dat /u/bb/test3.dat /u/cc/test4.dat Pls help Thanks (6 Replies)
Discussion started by: thumsup9
6 Replies
Login or Register to Ask a Question