find the position in a file and insert the data there


 
Thread Tools Search this Thread
Operating Systems HP-UX find the position in a file and insert the data there
# 1  
Old 04-10-2006
find the position in a file and insert the data there

Hi,

I have a EDI data file ARROWTEST of size 18246 characters. And I want to insert some data after 4200 position in the file. How I can find the position 4200 in that file....Please advise.

Regards,
# 2  
Old 04-10-2006
Try using split -b, e.g...
Code:
split -b 4200 infile  tmpfile.
for file in tmpfile.??
do
    cat $file
    if [[ $file = tmpfile.aa ]]
    then
       printf "additional data goes here"
    fi
done > outfile
rm tmpfile.??

# 3  
Old 04-11-2006
Quote:
Originally Posted by Ygor
Try using split -b, e.g...
Code:
split -b 4200 infile  tmpfile.
for file in tmpfile.??
do
    cat $file
    if [[ $file = tmpfile.aa ]]
    then
       printf "additional data goes here"
    fi
done > outfile
rm tmpfile.??

this would reduce the overhead of file comparison,
once data is pumped after 4200 bytes,

>w.ksh
Code:
split -b 4200 infile  tmpfile.
cat tmpfile.aa
echo "pump data"
cat tmpfile.a[!a]


Code:
>./w.ksh > outputfile

but would file for split commands generating more than 26 files...
# 4  
Old 04-11-2006
I fail to see the point of changing my script to one that is uglier, more limited and leaves temp files behind.
# 5  
Old 04-11-2006
yes,

i should have included
/bin/rm tmpfile.??

Quote:
More Limited !!!
If that is so... how would your current script handle situations if it had to generate more than 676 files? (Anyway solution to that bottleneck is also available)
# 6  
Old 04-11-2006
Your script is limited to 26 files and mine is limited to 676 files. So your script is more limited.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Column to row and position data in a text file

Hi everyone.. I have a list of values in a file... a, b, c, 1, 2, 3, aaaa, bbbbb, I am interested in converting this column to a row.. "text",aaaa, bbbb a,1 (7 Replies)
Discussion started by: manihi
7 Replies

2. Shell Programming and Scripting

Add '|' to data file on particular position

I have below scenario where i am getting a flat file but with some bad data incoming data format id|name|ind|crncy 123|xxx|y|usd 234|yy|n| 456|a|y90.5|vvv|gbp ----bad dataneed to cleanse the bad data above by adding a pipe '|' after 3rd column 'ind' if pipe '|' is not already there ... (1 Reply)
Discussion started by: rakesh5300
1 Replies

3. UNIX for Dummies Questions & Answers

Need to copy data from one position to another in file

Hi. I need to write a script that will allow me to copy data from one position in a line to another position while changing the first 2 bytes of the data to a constant. Here is an example of a line of data before and what it needs to look like after. there are about 200 lines in the file. ... (1 Reply)
Discussion started by: wlb_shore_user
1 Replies

4. Shell Programming and Scripting

Find the starting position in a file

I have a file called "INPUT" which takes the following format MNT-BANK-NUMBERO:006,00:N MNT-100-ACCOUNT-NUMBERO:018,00:N MNT-1000-DESCRIPTIONO:045:C . . . Now i got to find the displacements of the account numbers of each field of a file. For the field MNT-BANK-NUMBERO:006,00:N, the... (4 Replies)
Discussion started by: bobby1015
4 Replies

5. Shell Programming and Scripting

How to find character position in file?

how to find character positionin file? i.e string = "123X568" i want to find the position of character "X". Thanks (6 Replies)
Discussion started by: LiorAmitai
6 Replies

6. Shell Programming and Scripting

Insert file contents into another file at a given position

I'm trying to write a small shell script/command to insert the contents of one file into another file at a position marked with a given text string. It's not necessarily at the top or bottom of the file so I can't just use cat to cat the files together. I think probably sed with the r option is... (5 Replies)
Discussion started by: shaun29
5 Replies

7. Shell Programming and Scripting

Insert character in a specific position of a file

Hi, I need to add Pipe (|) at 5th and 18th position of all records a file. How can I do this? I tried to add it at 5th position using the below code. It didnt work. Please help!!! awk '{substr($0,5,1) ~ /|/}{print}' $input_file > $temp_file (1 Reply)
Discussion started by: gpaulose
1 Replies

8. UNIX for Dummies Questions & Answers

find if a position is between a given start and end position

Hi, I am a newbie in unix programming so maybe this is a simple question. I would like to know how can I make a script that outputs only the values that are not between any given start and end positions Example file1: 2 30 40 80 82 100 file2: ID1 1 ID2 35 ID3 80 ID4 81 ID6... (9 Replies)
Discussion started by: fadista
9 Replies

9. 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

10. Shell Programming and Scripting

How to insert at a particular position in flat file

Hi All, I have a flat file with ~ as de-limiter (e.g: aaa~ba a~caa~0~d~e) What I want is check if the 4th character is 0 and replace it with say 4. So now it becomes : aaa~ba a~caa~4~d~e. I have to do this for the whole file, but the delimiter position remains the same, not the... (10 Replies)
Discussion started by: akdwivedi
10 Replies
Login or Register to Ask a Question