The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
a bit tricky to change it multiple rows in one row and ... netbanker Shell Programming and Scripting 2 01-01-2008 01:48 AM
Tricky Shell script namishtiwari Shell Programming and Scripting 61 08-23-2007 07:26 AM
tricky search replace: Pls help. vaibhavs Shell Programming and Scripting 5 06-11-2007 03:44 PM
Tricky script question budrito Shell Programming and Scripting 3 06-30-2006 04:06 AM
Tricky one... saabir Windows & DOS: Issues & Discussions 1 12-12-2002 05:34 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-22-2005
bestbuyernc bestbuyernc is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 18
Tricky Sed

Hello. I am trying to convert occurrences of 'NULL' from a datafile. The 'NULL' occurences appears at this:

|NULL| NULL|NULL| NULL|NULL| NULL|NULL| NULL|

There should be 52 fields per line.
I would like any occurrence of | NULL| or |NULL| to appear as '||'
Currently I am using this sed command to convert:


Code:
/usr/bin/sed -e '1,2d' -e '/^$/d' -e '$d' ${DATA}/in1.bcp > ${DATA}/trash.bcp
/usr/bin/sed -e 's/^.//g' -e 's/  */ /g' -e 's/|$//g' -e 's/000|/0|/g' -e 's/ |/|/g' ${DATA}/trash.bcp > ${DATA}/out1.bcp
/usr/bin/sed -e 's/|NULL|/|/g' -e 's/|*NULL|/|/g' ${DATA}/out1.bcp > ${DATA}/final.bcp

The problem is some fields come out like '| |' and the number of fields do not equal 52. They vary depending on how many occurrences where converted per line.

Thank you for your help.
  #2 (permalink)  
Old 11-22-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
Look at this from your last line:
-e 's/|NULL|/|/g' -e 's/|*NULL|/|/g'
If I understand what you want, you should be doing
-e 's/|NULL|/||/g' -e 's/|*NULL|/||/g'

Except that first command handles stuff also handled by the second command. Remember that * means zero or more.
  #3 (permalink)  
Old 11-22-2005
grasper grasper is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 45
Your code seems to be doing various things but for the problem you describe, why not just divide your sed statement into 2 commands, one that removes 'NULL's and the other that removes spaces.


sed -e 's/ //g' -e 's/NULL//g'
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0