02-22-2013
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?
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
using sed to replace a specific string on a specific line number using variables
this is where i am at
grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean
grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies
2. Shell Programming and Scripting
Hello ,
I need to extract data from specific byte positions of a file.
I have tried the below command
awk ' { printf "%s", substr($0, 642363,642369}' filename
to extract data between byte positions
642363 and 642369 .
However I did not get the expected result.
I am new to awk... (6 Replies)
Discussion started by: rmv
6 Replies
3. Shell Programming and Scripting
I am attempting to replace positions 44-46 with YYY if positions 48-50 = XXX.
awk -F "" '{if (substr($0,48,3)=="XXX") $44="YYY"}1' OFS="" $filename > $tempfile
But this is not working, 44-46 is still spaces in my tempfile instead of YYY. Any suggestions would be greatly appreciated. (9 Replies)
Discussion started by: halplessProblem
9 Replies
4. Shell Programming and Scripting
From the existing file, I need to replace specific contents possibly with var every time when the user changes the var.
e.g the contents in the file file.txt is 'My name is $n and I am $y years old' and every time user changed the var outside the file, the contents of the file should be created... (4 Replies)
Discussion started by: Emilywu
4 Replies
5. Shell Programming and Scripting
I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work.
Brief overview:
I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies
6. Shell Programming and Scripting
my requirement is,
consider a file output
cat output
blah sdjfhjkd jsdfhjksdh
sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf
hellow there
this doesnt look good
et cetc etc
etcetera
i want to replace a line of line number 4 ("this doesnt look good") with some other line
... (3 Replies)
Discussion started by: vivek d r
3 Replies
7. Shell Programming and Scripting
Hello,
I have two files: file1 and file2
file1 has the following info:
---
host: "localhost"
port: 3000
reporter_type: "zookeeper"
zk_hosts:
- "localhost:2181"
file2 contains an IP address (1.1.1.1)
What I want to do is replace localhost with 1.1.1.1, so that the... (4 Replies)
Discussion started by: Jay Kah
4 Replies
8. Emergency UNIX and Linux Support
Hello,
My input file1 is like this by tab-delimited
chr1 mm10_knownGene stop_codon 3216022 3216024 0.000000 - . gene_id "uc007aeu.1"; transcript_id "uc007aeu.1";
chr1 mm10_knownGene CDS 3216025 3216968 0.000000 - 2 gene_id "uc007aeu.1"; transcript_id "uc007aeu.1"; ... (3 Replies)
Discussion started by: jacobs.smith
3 Replies
9. Shell Programming and Scripting
Hi,
I have a file with hundreds of lines. I want to search for particular lines starting with 4000, search and replace the 137-139 position characters; which will be '000', with '036'. Can all of this be done without opening a temp file and then moving that temp file to the original file name.
... (7 Replies)
Discussion started by: dsid
7 Replies
10. UNIX for Beginners Questions & Answers
I have a fixed-length positional file. I am trying to replace content of position 4-13 (length=10) with xxxxxxxxxx.
Sample 2 rows in this file:
H0187459823 172SMITH, JOE
H0112345678 172DOE, JANE
In this example 87459823 (from 1st line) and 12345678 (from 2nd line) (both in position... (3 Replies)
Discussion started by: Diver181
3 Replies
LEARN ABOUT HPUX
dteditorreplace
DtEditorReplace(library call) DtEditorReplace(library call)
NAME
DtEditorReplace -- replace a portion of the contents of a DtEditor widget
SYNOPSIS
#include <Dt/Editor.h>
DtEditorErrorCode DtEditorReplace(
Widget widget,
XmTextPosition startPos,
XmTextPosition endPos,
DtEditorContentRec *data);
DESCRIPTION
The DtEditorReplace function replaces part of the contents of a DtEditor widget with a string, a wide character string or sized buffer.
The data is transferred to the DtEditor widget using a DtEditorContentRec, which indicates the type of data being transferred along with
the actual data. All data following the start position and up to, but not including, the end position is replaced. If the start position
and the end position are equal, the data is inserted after the end position. The character positions begin at zero and are numbered
sequentially from the beginning of the text. After the replacement, the insertion cursor is positioned after the last character inserted.
The widget argument specifies the DtEditor widget ID.
The startPos argument specifies the starting character position of the portion to replace. The replacement begins at this character.
The endPos argument specifies the ending character position of the portion to replace. The replacement ends before this character.
The data argument is a pointer to the data structure containing the data to insert.
For a complete definition of the DtEditor widget and its associated resources, see DtEditor(3).
For a complete definition of DtEditorContentRec, see Dt/Editor.h - DtEditor(5).
RETURN VALUE
Upon successful completion, the DtEditorReplace function returns one of the following values:
DtEDITOR_NO_ERRORS
The data was replaced sucessfully.
DtEDITOR_NULLS_REMOVED
NULL characters were found and removed from the data.
Otherwise, if the DtEditorReplace function cannot replace the data in the DtEditor widget, it returns one of the following values:
DtEDITOR_INVALID_TYPE
The Type field is not recognized.
DtEDITOR_INVALID_RANGE
The startPos argument is greater than the endPos argument.
DtEDITOR_ILLEGAL_SIZE
The size of the buffer passed in is negative.
DtEDITOR_NULL_ITEM
The data buffer is NULL.
DtEDITOR_INSUFFICIENT_MEMORY
Not enough system memory is available to replace the data.
EXAMPLES
The following code segment modifies the contents of a DtEditor widget to ``The quick fox.''
Widget editor;
DtEditorContentRec cr;
DtEditorErrorCode status;
XmTextPosition start = (XmTextPosition) 4,
end = (XmTextPosition) 9;
char *sampleString1="The brown fox",
*sampleString2="quick";
cr.type = DtEDITOR_TEXT;
cr.value.string = sampleString1;
status = DtEditorSetContents(editor, &cr);
if (status != DtEDITOR_NO_ERRORS && status != DtEDITOR_NULLS_REMOVED) {
printf("Unable to set contents of the widget
");
} else {
cr.type = DtEDITOR_TEXT;
cr.data.string = sampleString2;
status = DtEditorReplace(editor, start, end, &cr);
if (status != DtEDITOR_NO_ERRORS)
printf("Unable to replace part of the widget contents
");
}
APPLICATION USAGE
If the data is in a disk file, rather than in memory, the application should use DtEditorReplaceFromFile(3).
SEE ALSO
Dt/Editor.h - DtEditor(5), DtEditor(3), DtEditorAppend(3), DtEditorAppendFromFile(3), DtEditorGetContents(3), DtEditorInsert(3), DtEdi-
torInsertFromFile(3), DtEditorReplaceFromFile(3), DtEditorSaveContentsToFile(3), DtEditorSetContents(3), DtEditorSetContentsFromFile(3).
DtEditorReplace(library call)