![]() |
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 |
| sort truncates line when they contain nulls | ArthurWaik | Shell Programming and Scripting | 6 | 04-22-2008 02:29 AM |
| How to check Null values in a file column by column if columns are Not NULLs | Mandab | Shell Programming and Scripting | 7 | 03-15-2008 09:57 AM |
| Blanks vs: Nulls | ebock | High Level Programming | 1 | 02-12-2008 05:16 PM |
| GREPing for Nulls | Dr. DOT | UNIX for Dummies Questions & Answers | 4 | 09-17-2004 03:28 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Replacing nulls using sed
Hi,
I am trying to replace nulls with spaces in every record of a '|' delimited file. I used this command - cat input.dat | sed 's/||/| |/g' > output But if a space appears twice '| | |' , then only the first null is getting replaced with a space. The second one remains as a null. I guess, this may be because I am not specifying the delimiter and checking for nulls. Can anyone help me out in this. Thanks a lot..!!! |
|
||||
|
I read that answer with interest. It does answer the OP's question.
But just on a side issue, why do we have to do this twice? Is it because the way sed works is that it will not reoperate on something it has just worked on in the same command? i.e. for the line: ||| the command Code:
sed 's/||/| |/g' | || and because the second | has been operated on, sed will not evaluate it, and therefore the new line containing || is not picked up. Is this right? thanks |
|
|||||
|
Quote:
|
|
||||
|
Thanks Vino for that answer.
But, having to do it twice will replace two consecutive nulls. This means that we have to repeat this operation as many times as the maximum number of consecutive nulls appearing in the row. Is there a way to make it replace nulls by giving it the delimiter '|' and asking it to replace null values? Again, thanks for your time. |
|
|||||
|
Quote:
I think awk can do it. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|