matching repeated character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting matching repeated character
# 1  
Old 12-13-2007
matching repeated character

looking for a bit of help with sed.

I have a file that looks a bit like this:
Code:
sdfghhjk
asdfdfghgj
asdfhgghj
werdfvtfh
edftbgh
1211211221
sdffgfm
dfghnhjm
dfvfsgbgh
adsfv bdhgn
1111111dffg
dfv1122
dsgvbghn111111
fffffffgbdghn
fffffff
sfgh3333gs vdf


I need to match any line that has a any character repeated more three or more times in a row.


so i need output like this:
Code:
1111111dffg
dsgvbghn111111
fffffffgbdghn
fffffff
sfgh3333gs vdf

# 2  
Old 12-13-2007
Wow!

I would do that in C, I'm sure plenty would do that in AWK.
# 3  
Old 12-13-2007
awk or sed is fine, i don't want to get in to C for this job.
# 4  
Old 12-13-2007
Code:
sed -n 's/\(.\)\1\1/&/p' myFile

# 5  
Old 12-13-2007
Quote:
Originally Posted by vgersh99
Code:
sed -n 's/\(.\)\1\1/&/p' myFile

dude you rock!!

thanks.
# 6  
Old 12-13-2007
Quote:
Originally Posted by vgersh99
Code:
sed -n 's/\(.\)\1\1/&/p' myFile

Nice,
or even:

Code:
grep '\(.\)\1\1'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk for matching fields between files with repeated records

Hello all, I am having trouble with what should be an easy task, but seem to be missing something fundamental. I have two files, with File 1 consisting of a single field of many thousands of records. I also have File 2 with two fields and many thousands of records. My goal is that when $1 of... (2 Replies)
Discussion started by: jvoot
2 Replies

2. UNIX for Beginners Questions & Answers

Matching fields between two files, repeated records

In two previous posts (here) and (here), I received help from forum members comparing multiple fields across two files and selectively printing portions of each as output based upon would-be matches using awk. I had been fairly comfortable populating awk arrays with fields and using awk's special... (3 Replies)
Discussion started by: jvoot
3 Replies

3. Shell Programming and Scripting

Find repeated word and take sum of the second field to it ,for all the repeated words in awk

Hi below is the input file, i need to find repeated words and sum up the values of it which is second field from the repeated work.Im trying but getting no where close to it.Kindly give me a hint on how to go about it Input fruits,apple,20,fruits,mango,20,veg,carrot,12,veg,raddish,30... (11 Replies)
Discussion started by: 100bees
11 Replies

4. Shell Programming and Scripting

pattern matching on any special character in Unix

Hi, I have field in a file which would come with any special character, how do i check that field? Eg: @123TYtaasa>>>/ 131dfetr_~2 In the above example, how do I add pattern for any special character on the keyboard. Thanks (3 Replies)
Discussion started by: techmoris
3 Replies

5. Shell Programming and Scripting

removing items with repeated first 3 character

AWK help: I have a file with following format. I need to remove any entries which are repeated based on first 3 characters. So from the following files I need to remove any entries start with "mas". mas01bct mas02bct mas03bct mas01bct mas01bct mas01bct mas11bct mas01bct mas01bct... (11 Replies)
Discussion started by: amir07
11 Replies

6. Shell Programming and Scripting

Matching multiples of a single character using sed and awk

Hi, I have a file 'imei_01.txt' having the following contents: $ cat imei_01.txt a123456 bbr22135 yet223 where I want to check whether the expression 'first single alphabet followed by 6 digits' is present in the file (here it is the first record 'a123456') I am using the following... (5 Replies)
Discussion started by: royalibrahim
5 Replies

7. UNIX for Dummies Questions & Answers

Matching character

Alright, I am stuck here. I have this variable that stores the word = HELLO and I have converted it it to ----- I have asked user to input one character at a time. SAy, if they enter E. Therefore, I need to search 2nd character and input E there. makes it -E--- (other checkings have been... (2 Replies)
Discussion started by: felixwhoals
2 Replies

8. Shell Programming and Scripting

tcl: regexp matching special character

Hello Experts, Can someone help me here: I have a variable which contains a string with "". set var1 {a} set str1 {a is the element i want to match} Now "regexp $var1 $str1" does not work? ("regexp {a\} $str1" works, but var1 gets it's value automatically from another script) Is... (6 Replies)
Discussion started by: sumitgarg
6 Replies

9. Shell Programming and Scripting

Matching a choice of character in test command

Hi ] && exit 0 Although it, the $answer, is 'y', the test operation returns true. && exit 0 This works but I want to do multiple choice matching. I don't want to do like: Please help (2 Replies)
Discussion started by: lalelle
2 Replies

10. UNIX for Dummies Questions & Answers

character matching

Is there a way to pull out a character at a time from a work in unix, using a shell script? (1 Reply)
Discussion started by: Rukshan
1 Replies
Login or Register to Ask a Question