![]() |
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 |
| stop unix find on a directory structure after finding 1st occurrence | jm0221 | Shell Programming and Scripting | 3 | 06-06-2008 07:19 PM |
| help with finding & replacing pattern in a file | dusoo | Shell Programming and Scripting | 0 | 05-23-2008 03:59 AM |
| replacing certain characters with new line? | Bashar | Shell Programming and Scripting | 4 | 05-13-2007 04:34 PM |
| finding & replacing blank rows/spaces in a file | Gerry405 | SUN Solaris | 2 | 07-21-2005 04:49 AM |
| shellscript for finding and replacing in DG-UNIX | Gerry405 | UNIX for Dummies Questions & Answers | 3 | 07-12-2005 08:12 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Finding nth occurrence in line and replacing it
Hi,
I have several files with data that have to be imported to a database. These files contain records with separator characters. Some records are corrupt (2 separators are missing) and I need to correct them prior to importing them into the db. Example: |field1|field2|field3|field4|field5|field6|field7|field8|field9|field10|field11|field12||| |field1|field2|field3|field4|field5|field6|field7|field8|field9|field10|field11|field12|field13|fiel d14|field15 |field1|field2|field3|field4|field5|field6|field7|field8|field9|field10|field11|field12|field13 The records 1 and 2 are correct. They consist of 15 optional fields separated by 15 | characters. Record 3 is corrupt since it's missing 2 separator characters ahead field13. It should look like: |field1|field2|field3|field4|field5|field6|field7|field8|field9|field10|field11|field12|||field13 How can I achieve this by using sed or awk or something else? Any help is greatly appreciated! TIA, Stephan. |
|
||||
|
Hey, thanks for your fast reply!
I don't care about pretty solutions - it works and that's important to me! I just tested on my real file and that's what I looked for! Maybe one day I have the time to pimp the statement - but I won't win a prize as well... ![]() Thanks again! |
|
||||
|
Wow, that's a really nice solution. I never would have found that on my own - of course, that's the reason why I post to the Dummies forum...
Thank you! |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|