Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

sed to replace specific positions on line with file contents

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 02-22-2013
balajesuri's Unix or Linux Image
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 25 May 2015, 12:34 PM EDT
Location: India
Posts: 1,886
Thanks: 27
Thanked 539 Times in 516 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 Unix and Linux 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 03:34 PM
How to replace specific contents in a file? Emilywu Shell Programming and Scripting 4 02-14-2011 06:50 PM
awk script replace positions if certain positions equal prescribed value halplessProblem Shell Programming and Scripting 9 09-15-2010 10:35 AM
Need specific byte positions of a file rmv Shell Programming and Scripting 6 10-13-2009 06: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 09:40 PM



All times are GMT -4. The time now is 03:39 AM.