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
need help with replacing a certain field... shennanigan83 Shell Programming and Scripting 5 04-09-2008 02:00 AM
Replacing text chrchcol Shell Programming and Scripting 3 07-25-2006 01:30 PM
Replacing certain field charbel Shell Programming and Scripting 1 04-26-2006 05:00 PM
replacing text ajaya Shell Programming and Scripting 2 04-12-2006 01:31 PM
Replacing the last field of a line. Darek Shell Programming and Scripting 3 08-19-2005 12:45 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 08-27-2007
DarkHound DarkHound is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 3
replacing a nul field with text

Ok here's my pickle. I have a file in which every line must be the same length. Each field within the line is a certain length. None of these can be changed. What I need to do is look at a specific field within this file, let's say it starts with character 30 and ends with 50. If this field is empty, I need it to be replaced with a bit of text.

An example. Note that field 3 below in the first line is blank. I need to make it look like line2. Also, it should ignore the line if there is anything at all in the field as in line 2 and 3.


Code:
field1field2                       field4
field1field2field3                field4
field1field2sometext           field4


Any help would be appreciated as I'm horrible with sed.

Last edited by DarkHound; 08-27-2007 at 09:41 AM.. Reason: Wanted to fix offsets, apparently the board [code] tags do not use monospaced fonts.
  #2 (permalink)  
Old 08-27-2007
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Bangalore
Posts: 219
Could you please also show us the output so that it would be helpful for us to provide the code. how many characters would be there in field 3? do you want to remove all the white spaces?
  #3 (permalink)  
Old 08-27-2007
DarkHound DarkHound is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 3
Unfortunately I can't provide an example, it's confidential patient data and can't exactly be sanitized. I can however provide what character/column the field begins and ends at. The field starts at colum 308 and ends at column 327. Instead of being blank, I want the field to contain "See Free Text" without the quotes.

No I do not want to change the size of the line in any way. The field, nor the line containing the field can not change in size, otherwise the importer has a fit.
  #4 (permalink)  
Old 09-04-2007
DarkHound DarkHound is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 3
FYI, I figured it out through use of another resource. The following is what did the trick, just in case anyone else needs to know.

perl -pe 's/^(.{307})\s{20}/$1SEE FREE TEXT /' input.file > output.file
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 10:17 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