Sponsored Content
Top Forums Shell Programming and Scripting Search for a string at a particular position and replace with blank based on position Post 302955376 by Don Cragun on Wednesday 16th of September 2015 10:17:22 PM
Old 09-16-2015
Note that using:
Code:
printf (substr($0,1,358) " " substr($0,360,length($0)) "\n")

and:
Code:
printf ($0 "\n")

is very dangerous and can produce diagnostic messages or mangled output, and maybe also terminate your awk script instead of producing the output you want if there are any <percent-sign> or <backslash> characters in the input file you are processing. For your own safety, please change the above printf statements in your awk script to something more like:
Code:
printf("%s", substr($0,1,358) " " substr($0,360) "\n")
    or
printf("%s %s\n", substr($0,1,358),  substr($0,360))

and:
Code:
printf("%s", $0 "\n")
    or
printf("%s\n", $0)
    or much more simply
print $0
    or even just
print

respectively.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to find a position and print some string in the next and same position

I need a script for... how to find a position of column data and print some string in the next line and same position position should find based on *HEADER8* in text for ex: ord123 abs 123 987HEADER89 test234 ord124 abc 124 987HEADER88 test235 ... (1 Reply)
Discussion started by: naveenkcl
1 Replies

2. Shell Programming and Scripting

Search for a string and replace the searched string in the same position

Hi All, My requisite is to search for the string "0108"(which is the year and has come in the wrong year format) in a particular column say 4th column in a tab delimited file and then replace it with 2008(the correct year format) in the same position where 0108 was found..The issue is the last... (15 Replies)
Discussion started by: ganesh_248
15 Replies

3. UNIX for Dummies Questions & Answers

Search for a string and replace the searched string in the same position in samefile

Hi All, My requisite is to search for the string "0108"(which is the year and has come in the wrong year format) in a particular column say 4th column in a tab delimited file and then replace it with 2008(the correct year format) in the same position where 0108 was found in the same file..The... (27 Replies)
Discussion started by: ganesh_248
27 Replies

4. Shell Programming and Scripting

Replace strings based on position and length?

Suppose i have a file which contains thousands of records. e.g adjgmptjadmwpgjmwmd i need to replace the string from 3rd to 8th position using awk script in entire file. And also the positions will be passed as parameter. (3 Replies)
Discussion started by: laknar
3 Replies

5. UNIX for Dummies Questions & Answers

Replace based on an exact position

Trying to use sed - but having no luck. I have a text file - I want to replace whatever character is in position 106, 157 and 237 w/ the string "xxx". Want this change for all lines w/in that text file. I'm open to using awk or whatever command would be best for replacing characters based... (5 Replies)
Discussion started by: svn
5 Replies

6. UNIX for Dummies Questions & Answers

Search a string in the file and then replace another string after that position

Hi I am looking for a particular string in a file.If the string exists, then I want to replace another string with some other text.Once replaced, search for the same text after that character position in the file. :wall: E.g: Actual File content: Hello Name: Nitin Raj Welcome to Unix... (4 Replies)
Discussion started by: dashing201
4 Replies

7. Shell Programming and Scripting

Search and Replace by record position

Hi All, I have a file that I would like to search for data and replace other data by record position number: Example search.. search for "CLARK KENT" and replace Amt data "000025" with "000155"??? I'm able to search and replace unique data but, came to a stump when wanting to replace data... (11 Replies)
Discussion started by: macastor
11 Replies

8. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

9. Shell Programming and Scripting

Fixed width file search based on position value

Hi, I am unable to find the right option to extract the data in the fixed width file. sample data abcd1234xgyhsyshijfkfk hujk9876 io xgla loki8787eljuwoejroiweo dkfj9098 dja Search based on position 8-9="xg" and print the entire row output ... (4 Replies)
Discussion started by: onesuri
4 Replies

10. Shell Programming and Scripting

How to search for blank fields in a text file from a certain position?

Sample txt file : OK00001111112| OK00003443434|skjdaskldj OK32812983918|asidisoado OK00000000001| ZM02910291029|sldkjaslkjdasldjk what would be the shell script to figure out the blank space (if any) after the pipe sign? (4 Replies)
Discussion started by: chatwithsaurav
4 Replies
DtEditorReplaceFromFile(library call)									     DtEditorReplaceFromFile(library call)

NAME
DtEditorReplaceFromFile -- replace a portion of the contents of a DtEditor widget with the contents of a file SYNOPSIS
#include <Dt/Editor.h> DtEditorErrorCode DtEditorReplaceFromFile( Widget widget, XmTextPosition startPos, XmTextPosition endPos, char *fileName); DESCRIPTION
The DtEditorReplaceFromFile function replaces part of the contents of a DtEditor widget with the contents of a file. 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 fileName argument is the pathname of the file relative to the local system. For a complete definition of the DtEditor widget and its associated resources, see DtEditor(3). RETURN VALUE
Upon successful completion, the DtEditorReplaceFromFile function returns one of the following values: DtEDITOR_NO_ERRORS The file is readable and writable. DtEDITOR_READ_ONLY_FILE The file is read only. DtEDITOR_NULLS_REMOVED The file contained embedded NULL characters, which were removed. Otherwise, if it cannot insert the data into the DtEditor widget, the function returns one of the following values: DtEDITOR_INVALID_RANGE The startPos argument is greater than the endPos argument. DtEDITOR_NONEXISTENT_FILE The file does not exist. DtEDITOR_DIRECTORY The file is a directory. DtEDITOR_CHAR_SPECIAL_FILE The file is a character-special device. DtEDITOR_BLOCK_MODE_FILE The file is a block-mode device. DtEDITOR_NO_FILE_ACCESS The file cannot be accessed. DtEDITOR_INSUFFICIENT_MEMORY Not enough system memory is available to replace the data. DtEDITOR_UNREADABLE_FILE The file is unreadable for an unspecified reason. APPLICATION USAGE
If the data is in memory, rather than a disk file, the application should use DtEditorReplace(3). SEE ALSO
Dt/Editor.h - DtEditor(5), DtEditor(3), DtEditorAppend(3), DtEditorAppendFromFile(3), DtEditorGetContents(3), DtEditorInsert(3), DtEdi- torInsertFromFile(3), DtEditorReplace(3), DtEditorSaveContentsToFile(3), DtEditorSetContents(3), DtEditorSetContentsFromFile(3). DtEditorReplaceFromFile(library call)
All times are GMT -4. The time now is 02:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy