![]() |
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 |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Parsing string using specific delimiter | primp | Shell Programming and Scripting | 8 | 09-22-2008 01:46 AM |
| string replacement in a sequence of characters | raoscb | UNIX for Dummies Questions & Answers | 3 | 07-08-2008 06:00 AM |
| Adding a sequence string to a file | MrPeabody | Shell Programming and Scripting | 5 | 07-21-2006 03:50 PM |
| Searching for a specific string in an argumnet | dinplant | Shell Programming and Scripting | 1 | 03-11-2002 03:28 PM |
| Search all files for specific string | sureshy | UNIX for Dummies Questions & Answers | 4 | 03-06-2002 12:28 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
cmd sequence to find & cut out a specific string
A developer of mine has this requirement - I couldn't tell her quickly how to do it with UNIX commands or a quick script so she's writing a quick program to do it - but that got my curiousity up and thought I'd ask here for advice.
In a text file, there are some records (about half of them) that have a specific string, say "ABC" followed by a 15 digit number, always at least 2 leading zeros. In rows that have this, it will appear twice, identically. I essentially want to cut out these 18 chars into a file of their own. But, they are not in a fixed column position within the file. Logically, the task is: a) find the rows with ABC00 b) get the position of that first A c) cut starting at that position for 18 characters and write to a new file. example data: ab cdefgABC000000000012345ABC000000000012345sadlfk abcde fgABC000000000012346ABC000000000012346sadlfk abc defgghi jklmn1349d5sadlfk abcdef sldkfdgABC000000000056789ABC000000000056789abcdlkdfj134239d and so on. Desired output ABC00000000012345 ABC00000000012346 ABC00000000056789 Thanks for having a look. Lisa |
|
|||||
|
You found a solution and verified it works.
Most every problem has already been pondered and solved, so there truly are no "new" answers. Ha ha Back to the initial problem, the creative use of sed to place extra characters and then tr to convert them so a grep and cut can extract them -- is one useful process to pull apart data records. Let him think you were the genius. |
|
||||
|
Inevitably, a perl approach
![]() Code:
perl -ne '/(ABC00\d{13})/ && print "$1\n"' list.txt
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| unix commands |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|