-3

My file looks like

cat new:

ALL          ALLOFTHEM    ALL1
OPS     BE2A    OPS1

 ABE    ABE     ABE1

sed query below gives me the result as 1st line sed -n '/\([A-Z]\{1,\}\)\1/p' new:

ALL          ALLOFTHEM    ALL1

I guessed that 2nd line would also match as OPS is also a character length more than 1.

Any ideas?

closed as unclear what you're asking by Anthon, slm, strugee, iruvar, Thomas Nyman Apr 10 '14 at 5:43

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Any ideas is a very generic question, almost always answerable by yes (unless your heave in meditation and you can empty your mind). Try to reformulate the question into something like "how can I ...." that could give us a clue about what you are trying to achieve and would prevent correct, but unhelpful answers like "yes". – Anthon Apr 9 '14 at 20:52
2

I guessed that 2nd line would also match as OPS is also a character length more than 1.

So, you want to match on any line that has more than one consecutive capital letters? If so, use:

$ sed -n '/[A-Z]\{2,\}/p' new
ALL          ALLOFTHEM    ALL1
OPS     BE2A    OPS1
 ABE    ABE     ABE1


Why doesn't your expression do that? Your regex is:

\([A-Z]\{1,\}\)\1

That breaks down into two parts. The first is \([A-Z]\{1,\}\) which matches one or more capital letters. The second part is \1 which matches the previous set of capital letters. This means that a pattern of capital letters has to be repeated (with no intervening characters) for there to be a match. That matches only the first line because the first line has a capital L followed by a capital L. It is the only line with such a sequence.

Not the answer you're looking for? Browse other questions tagged or ask your own question.