output strings to specific positions in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting output strings to specific positions in a file
# 1  
Old 05-24-2011
output strings to specific positions in a file

Been searching for about 3 hours for similar functionality that I can get examples of how to output text from variables into certain locations in a file. I would like to incorporate this into a script. I have not been able to find a command example that does it all in one method. I find part of it in sed, part of it in awk....etc.

What I am trying to do is prompt a user for some text. Then from a config file I will pull some X and Y coordinates for where to place the text in the file. I might have to loop a couple times to place more than one string to the respective location.

Example:
prompt user for text string one. the script will determine that this string should be put in the Nth line (let's say 2) and should start at the Nth space (let's say 10). For string two let's just say the values are line 4 and space 3.

essentially I am hoping to make a file that could basically be printed like a form from some user input and some known info from a config file or generated from the script. I would like to use KSH for the script. I guess any sed or awk solutions would be ok. Not sure what else could do this efficiently.

Thanks in advance!

So I would expect to get some output like:
---------------outline of output file--------------
|
| First string
|
| Second string
# 2  
Old 05-26-2011
Maybe, your paradigm is tricky. Is it sufficient to make a new file with parts of the old files selected by head or tail options?

Updating a file in place not at eof is the realm of a language like PERL or C. For instance, in C you can mmap64() the whole file and then just write it like a char[].
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace specific positions in a file

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

2. Shell Programming and Scripting

Search and replace specific positions of specific lines

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

3. UNIX for Beginners Questions & Answers

Extracting strings at various positions of text file

Hi Team - I hope everyone has been well! I export a file from one of our source systems that gives me more information than I need. The way the file outputs, I need to extract certain strings at different positions on the file and echo them to another file. I can do this in batch easily,... (2 Replies)
Discussion started by: SIMMS7400
2 Replies

4. UNIX for Beginners Questions & Answers

Using find to output list of files with specific strings

This is my problem, I am using the following code to extract the file names with specific strings 0.01: find ./ -name "*.txt" -exec grep -H '0.01' {} + It works wonders with a small sample. However, when I use it in a real scenario it produces an empty file -even though I am sure there are... (11 Replies)
Discussion started by: Xterra
11 Replies

5. Shell Programming and Scripting

Filter lines based on values at specific positions

hi. I have a Fixed Length text file as input where the character positions 4-5(two character positions starting from 4th position) indicates the LOB indicator. The file structure is something like below: 10126Apple DrinkOmaha 10231Milkshake New Jersey 103 Billabong Illinois ... (6 Replies)
Discussion started by: kumarjt
6 Replies

6. UNIX for Dummies Questions & Answers

Delete specific strings in a file

Hi, My file has a numerous sttrings.I want to retain those strings which start with stt and delete entries with >C For eg: my infile is >C4603985... (7 Replies)
Discussion started by: sa@@
7 Replies

7. Shell Programming and Scripting

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: I want to replace the 000000000178800 (positions 34 - 49) on this file with the contents of... (2 Replies)
Discussion started by: nwalsh88
2 Replies

8. Shell Programming and Scripting

Getting specific strings from output

so i have the following string: ... (3 Replies)
Discussion started by: SkySmart
3 Replies

9. Shell Programming and Scripting

Count specific characters at specific column positions

Hi all, I need help. I have an input text file (input.txt) like this: 21 GTGCAACACCGTCTTGAGAGG 50 21 GACCGAGACAGAATGAAAATC 73 21 CGGGTCTGTAGTAGCAAACGC 108 21 CGAAAAATGAACCCCTTTATC 220 21 CGTGATCCTGTTGAAGGGTCG 259 Now I need to count A/T/G/C numbers at each character location in column... (2 Replies)
Discussion started by: thienxho
2 Replies

10. Shell Programming and Scripting

Need specific byte positions of a file

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
Login or Register to Ask a Question