sed to replace specific positions on line with file contents | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

sed to replace specific positions on line with file contents

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-22-2013
nwalsh88 nwalsh88 is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 13 February 2014, 12:44 PM EST
Posts: 12
Thanks: 6
Thanked 0 Times in 0 Posts
sed to replace specific positions on line with file contents

Hi, I am trying to use an awk command to replace specific character positions on a line beginning with 80 with contents of another file.

The line beginning with 80 in file1 is as follows:

Quote:
80................................000000000178800.000010........................
I want to replace the 000000000178800 (positions 34 - 49) on this file with the contents of amended_file_01 -> 000000000206100

The command i am using is:

Quote:
sed '/^80/s/\(^.\{34\}\).\{15\}\(.*\)/\1$amended_file01\2/' file1
The output from this command should be
Quote:
80................................000000000206100.000010........................
But it is returning the filename instead of the file contents

Quote:
80................................$amended_file01.000010........................
How would i get the command to return the file contents instead of the filename?
Sponsored Links
    #2  
Old 02-22-2013
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 16 December 2014, 10:34 AM EST
Location: India
Posts: 1,837
Thanks: 25
Thanked 527 Times in 506 Posts
I hope you have code to store the contents of file "amended_file_01" into variable "amended_file01"; after which a minor adjustment to your sed one-liner should do the trick:

Code:
sed "/^80/s/\(^.\{34\}\).\{15\}\(.*\)/\1$amended_file01\2/" file1

The Following User Says Thank You to balajesuri For This Useful Post:
nwalsh88 (02-22-2013)
Sponsored Links
    #3  
Old 02-22-2013
nwalsh88 nwalsh88 is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 13 February 2014, 12:44 PM EST
Posts: 12
Thanks: 6
Thanked 0 Times in 0 Posts
Hi balajesuri,

That's perfect, thanks for your help
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace specific field on specific line sed or awk crownedzero Shell Programming and Scripting 14 11-27-2011 04:34 PM
How to replace specific contents in a file? Emilywu Shell Programming and Scripting 4 02-14-2011 07:50 PM
awk script replace positions if certain positions equal prescribed value halplessProblem Shell Programming and Scripting 9 09-15-2010 11:35 AM
Need specific byte positions of a file rmv Shell Programming and Scripting 6 10-13-2009 07:31 AM
using sed to replace a specific string on a specific line number using variables todd.cutting Shell Programming and Scripting 2 08-13-2009 10:40 PM



All times are GMT -4. The time now is 02:10 PM.