![]() |
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 |
| compare XML/flat file with UNIX file system structure | shafi2all | High Level Programming | 6 | 08-15-2008 02:15 AM |
| Use records from one file to delete records in another file | kenneth.mcbride | UNIX for Dummies Questions & Answers | 5 | 06-18-2008 02:36 PM |
| Flat file | Krishnaramjis | Shell Programming and Scripting | 9 | 05-08-2008 10:28 PM |
| Count No of Records in File without counting Header and Trailer Records | guiguy | Shell Programming and Scripting | 2 | 06-07-2007 12:15 PM |
| Inserting records from flat file to db table | Hara | Shell Programming and Scripting | 4 | 12-27-2006 03:35 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to delimit a flat file with records with SED
Hi gurus, hoping someone can help with a sed line that can do the following...
I have a flat file with about 1000 records, but in order to import into openoffice spreadsheet, I need to create a delimited file. I'd like to do 2 things with the SED command: 1- add a pipe character "|" at the end of each line 2- (the above will create a double pipe for every two blank links, such as ||). Replace the || double-pipe with carriage returns so in the end I have a delimited file. Im not rigid on how to perform step 2, so any recommendations are appreciated. See the file format below for a better view. The file format is like this: Person1 Address Value1 License Status blah blah blah <2 carriage returns> Person2 Address Value1 License status.. blah... <2 Carriage returns> etc... After running the text file through a SED command, i'd like the file to look like this: Person1|Address|Value1|License Status blah blah blah Person2|Address|Value1|License status.. blah... Person3|etc... Any help is greatly appreciated! Thanks in advance! |
|
||||
|
Hi, I'm not sure if it's OK with You but I would use a combination of tr and sed, because it feels natural, since You expressed the problem in two steps. First let tr replace each newline with | and then let sed replace double || with a newline, like this:
Quote:
/Lakris |
|
||||
|
Agree that tr plus sed is best
Only addition I'd make is that sed's substitute command will need to look for three pipes in a row as the two intervening newlines actually represent the second and third newlines in a row.
So, you'd want tr "\n" "|" < input.txt | sed 's/|||/\n/g' |
![]() |
| Bookmarks |
| Tags |
| delimiter, linux, sed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|