![]() |
|
|
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 use sed to search for string and Print previous two lines and current line | nmadhuhb | Shell Programming and Scripting | 1 | 07-30-2009 09:35 AM |
| Append each line to next previous line in a file | sudhakaryadav | Shell Programming and Scripting | 8 | 06-01-2009 12:21 PM |
| remove lines based on score criteria | smriti_shridhar | Shell Programming and Scripting | 2 | 12-02-2008 01:03 AM |
| append the line with the previous if it not start with 1= | palsevlohit_123 | UNIX for Advanced & Expert Users | 3 | 11-12-2008 04:58 AM |
| Select records based on search criteria on first column | shashi_kiran_v | UNIX for Dummies Questions & Answers | 2 | 12-02-2005 01:49 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Append specific lines to a previous line based on sequential search criteria
I'll try explain this as best I can. Let me know if it is not clear. I have large text files that contain data as such: Code:
143593502 09-08-20 09:02:13 xxxxxxxxxxx xxxxxxxxxxx 09-08-20 09:02:11 N line 1 test line 2 test line 3 test 143593503 09-08-20 09:02:13 xxxxxxxxxxx xxxxxxxxxxx 09-08-20 09:02:10 N another message Every line in the file that starts with a 9 digit number (followed by a date / time and so on) is a unique message. In the example the first 3 lines are really 1 message (with 2 newlines in it). This first 9 digit number increments sequentially. What I want to do is get each message in it's entirety onto 1 line. So I *want* the file to look like: Code:
143593502 09-08-20 09:02:13 xxxxxxxxxxx xxxxxxxxxxx 09-08-20 09:02:11 N line 1 test line 2 test line 3 test 143593503 09-08-20 09:02:13 xxxxxxxxxxx xxxxxxxxxxx 09-08-20 09:02:10 N another message Note that I'd like there to be a space between the additional lines in a single message. My first idea was to remove ALL newlines from the file and replace them with spaces, and then work through that data inserting a newline after each of the sequence numbers. I believe this will solve the problem but unfortunately I don't have the chops to pull it off. I'm sure there are also other, potentially better, ways of solving the problem. One potential issue, I suppose, would be if one of the "extra" lines in a single message was miraculously the next 9 digit number in the sequence itself. I believe the chances of this would be pretty slim, probably to the extent of making this a moot concern for me at this point... but nonetheless it's something to consider. Ideally I would like to do this with either perl or bash. Thanks. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|