![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to replace any char with newline char. | mightysam | Shell Programming and Scripting | 5 | 09-18-2008 08:15 PM |
| extraction of last but one char in a line | hidnana | Shell Programming and Scripting | 1 | 02-14-2008 08:48 AM |
| AWK extraction | harris2107 | Shell Programming and Scripting | 2 | 01-15-2008 11:44 AM |
| AWK extraction | harris2107 | Shell Programming and Scripting | 3 | 08-17-2007 05:02 AM |
| Help with tar extraction! | manthasirisha | Shell Programming and Scripting | 4 | 03-17-2006 07:17 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
extraction of last but one char
I need to extract the character before the last "|" in the following lines, which are 'N' and 'U'. The last "|" shouldn't be extracted. Also the no.s of "|" may vary in a line, but I need only the character before the last one.
TT-CAP-N241485-0005241485|ADMINISTRATOR|INC_ORGANISATION_NAME|SUPERIOR_TITLE_1|REV|FIRST_NAME_1|MIDDLE_NAME_1|SURNA ME_FIELD|INC ADDRESSS 1|INC ADDRESSS 2|INC ADDRESSS 3|INC ADDRESSS 4|INC ADDRESSS 5|INC ADDRESSS 6|IN123EC|MALTA|Y||M||Y|LIFEASSURED 2|Y|N||||||||||||||||||||||||Y||Y||||||||||||PRU|A||289832|||FCBGFBF|Y|Y|1|DC|1|1|3|Y|O||20300601||| CAP|5649369|VVUMU7SMT0|HCBCBFDJF|N|Y|N|Y|Y|N|Y|Y|N|3||6|C|20051205|555555555|||||20070604|4|15||C|0| 9|4527|0||20071109|4|C|982062|23569837|36657407|9096||20071205|1|N| TT-CAP-5241492-0005241492|ADMINISTRATOR1|INC_ORGANISATION_NAME|SUPERIOR_TITLE_1|MS|FIRST_NAME_1|MIDDLE_NAME_1|SURNA ME_FIELD|INC ADDRESSS 1|INC ADDRESSS 2|INC ADDRESSS 3|INC ADDRESSS 4|INC ADDRESSS 5|INC ADDRESSS 6|IN123EC||N||F||N|LIFE ASSURED 1|Y|N||||||||||||||||||||||||Y||Y||||||||||||PRU|BFF||200006|||EB|Y|Y|3|DC|2|1|3|Y|O||20301207|||CAP |5649376|ZLBFQDGVGIOIJDHKNDK|F|N|Y|Y|N|Y|N|N|Y|N|4||7|C|20051205|555555555|||||20070604|2|1600770||B |281215|66|124002|923545||20060405|1|C|1446100|92811|64148521|5||20071205|1|U| I'm not able to achieve it by cut command. How can it be done ? Last edited by hidnana; 02-14-2008 at 06:06 AM.. |
|
||||
|
As the pipe symbol is the last char in the line it is matched by "|$". From there it is easy to construct the following regexp:
sed 's/.*\([NU]\)|$/\1/' i hope this helps bakunin |
|
||||
|
You are right of course. I wouldn't have limited it if the thread-starter wouldn't have explicitly stated that the character could only be "N" or "U".
Perhaps it is a matter of programming philosophy (which is not the topic of this thread - at least not directly), i would prefer my solution over the general one followed by a line catching all the lines not matched by my solution to point them out as suspicious - lines which "shouldn't exist" at all. The point is: if a specification says that the specific character can only be "N" or "U", then i would like to be informed if a line with neither "N" or "U" on it comes up. Maybe the specification has changed, maybe my script is faulty, maybe some pre-processing steps producing the lines are faulty - whatever. At least there is *something* that might have to be dealt with. With all due respect bakunin |
|
||||
|
Thanks for your valuable suggestions.
|
| Sponsored Links | ||
|
|