grep lines with two specific characters somewhere in the line

Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers grep lines with two specific characters somewhere in the line
# 1  
Old 09-11-2009
grep lines with two specific characters somewhere in the line

I'm having trouble with extracting certain lines from a file based on whether they have all the required fields.

Original file:
snt:594:Sam N This
bpt:2342:Bob P That
wrp:23:Whoever Person

Desired output:
snt:594:Sam N This
bpt:2342:Bob P That
wrp:23:Whoever Person

I've searched and I haven't been able to find anything to target only these lines. The only thing I can think of is this but it doesn't work:
grep ":*:" < temp

Last edited by vgersh99; 09-11-2009 at 01:24 PM.. Reason: code tags, PLEASE!
# 2  
Old 09-11-2009
grep '.*:.*:.*' myFile
nawk -F: 'NF==3' myFile

# 3  
Old 09-11-2009
That's exactly what I was looking for. Thanks!
# 4  
Old 09-11-2009
To understand it better, you are missing . (dot) thats all. Previously you had :* which meant zero or more :.

 grep ":.*:" t1

The above will also work, if the input you had given is as similar as you had given in your 1st post.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep content between specific lines

cat file1 *FileHeader* Partition 0 Total Data Bytes 1416 Avg Bytes/Record 1416 Others 1 PRDX22.AUDIT_DATA_INFO Partition 4 Total Data Bytes 4615 Avg... (8 Replies)
Discussion started by: Veera_V
8 Replies

2. UNIX for Dummies Questions & Answers

Grep specific lines

Hello I have a file with nearly 90000 lines in x,y,z format but have some lines that I do not need to show. Is there anyway to delete those 3 lines after every 288 lines. Eg I keep the first 288 lines delete (289, 290 291); keep the next 288 lines after those and so on... Thanks (6 Replies)
Discussion started by: Madiouma Ndiaye
6 Replies

3. Shell Programming and Scripting

How delete characters of specific line with sed?

Hi, I have a text file with some lines like this: /MEDIA/DISK1/23568742.MOV /MEDIA/DISK1/87456321.AVI /MEDIA/DISK2/PART1/45753131.AVI /IMPORT/44452.WAV ... I want to remove the last 12 characters in each line that it ends "AVI". Should look like this: /MEDIA/DISK1/23568742.MOV... (12 Replies)
Discussion started by: inaki
12 Replies

4. Shell Programming and Scripting

grep the output between specific lines

Symmetrix ID : 00000001234 Host Name : myown Identifiers Found : 5000000000000000 5000000000000001 Device Cap(MB) Attr Dir:P ------ ------- ---- ---- 1234 25886 (M) 8D:1, 9D:1 0123 25886 (M) 8D:1, 9D:1 1345 25886 (M) ... (5 Replies)
Discussion started by: maddy.san
5 Replies

5. Shell Programming and Scripting

grep lines having special characters

Hi, I have a file which has numerous lines and some of the lines having special characters in it. i want to grep the lines which are having special characters. say, one line looks like - %*()$#@"", | acbd antoher line looks like ***##^%! | efcg so these kind of lines are present... (5 Replies)
Discussion started by: rbalaj16
5 Replies

6. Shell Programming and Scripting

Printing characters at specific position in line

Hi, I am trying to get an output like : +----------------------------------+ ----------- + + some variable substitution + some text + Is there a way I can specify in printf (in ksh) the particular position I want to print a character, and also repeat a character from... (1 Reply)
Discussion started by: neil.k
1 Replies

7. UNIX for Advanced & Expert Users

Grep returning partial lines due to special characters

Hey guys, I have a file with an ID which I'm using to grep out the original record from another file. Problem is I have special characters in the original file, and grep is returning only a partial record. How can I get around this? Appreciate your help! Pete (3 Replies)
Discussion started by: peteroc
3 Replies

8. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

9. Shell Programming and Scripting

Sed - merge lines bw 2 specific characters

Hi, I have a bash script and I am looking for a command that will merge specific lines together. Sample Data: registration time = 1300890272 Id = 1 setd = 0 tagunt = 26 tagId=6, length=8, value= tagId=9, length=5, value= tagId=7, length=2, value= tagId=16, length=2, value= tagId=32,... (8 Replies)
Discussion started by: Winsarc
8 Replies

10. Shell Programming and Scripting

Deleting Characters at specific position in a line if the line is certain length

I've got a file that would have lines similar to: 12345678 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 23456781 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 34567812 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 45678123 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 xx.00... (10 Replies)
Discussion started by: Cailet
10 Replies
Login or Register to Ask a Question