![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| extract the lines | prvnrk | Shell Programming and Scripting | 2 | 05-25-2008 03:17 AM |
| How to convert C source from 8bit chars to 16bit chars? | siegfried | Shell Programming and Scripting | 0 | 09-26-2007 11:26 AM |
| How to extract a sequence of n lines from a file | 0ktalmagik | Shell Programming and Scripting | 4 | 06-29-2006 08:24 PM |
| Extract known lines | nhatch | UNIX for Dummies Questions & Answers | 2 | 09-16-2004 08:59 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
sed to extract first two uppercase chars in targeted lines
Hello,
I have a file temp.txt: ------------------------- HELLO WORLD This is a temp file. TENCHARSHEre no beginning UPPERCHARS HI There ------------------------- What is a sed egrep command that will target lines that begin with 3-10 uppercase chars, and output the first 2 chars? desired result: --- HE TE --- So far I have been able to extract the targeted lines in egrep using the expression: egrep ^[A-Z]\{3,10\} < temp.txt . . but no luck in sed. Thank you |
| Forum Sponsor | ||
|
|
|
|||
|
Thank you for the reply..
However I have to do the following using egrep. I tried translating what you gave using -r: sed -r 's/^([A-Z][A-Z])[A-Z].*/\1/g' temp.txt Updated temp.txt: ------------------------- HELLO WORLD This is a temp file. TENCHARSHEre no beginning UPPERCHARS HI There ELEVENCHARActers ------------------------- desired output: HE TE actual output: HE This is a temp file. TE no beginning UPPERCHARS HI There EL 1) How do I ignore irrelevant targets? (i.e. "This is a temp file.", etc..) 2) It also includes 11 upperchars as the target. How do I restrict it to 10 uppercase chars only? Sed and regex are very difficult concepts for me to grasp, so I appreciate the patience and time. Thank you |