Edit locations in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Edit locations in a file
# 1  
Old 03-06-2014
Edit locations in a file

Hi ,
I have a file which looks like this

Code:
source1     LEN        predictive    392879  394347  0.955489        +       .       Name=sa000003.1;ID=sa000003;Alias=sa121751.1;
source1     LEN       descriptive_1   391082  392878  .       .       .       Parent=sa000003.1;supp_id=.1805.1;

source1      LEN        predictive    408863  416522  0.999853        -       .       Name=sa000004.1;ID=sa000004;
source1      LEN        descriptive_1   416523  416853  .       .       .       Parent=sa000004.1;supp_id=14.112.2;

source1     LEN        predictive    347320  348798  0.485927        -       .       Name=sa000006.1;ID=sa000006;Alias=sa121750.;
source1      LEN         descriptive_1   348799  351449  .       .       .       Parent=sa000006.1;supp_id=1800.1;
source1      LEN         descriptive_3   347154  347319  .       .       .       Parent=sa000006.1;supp_id=1800.1;

Basically ,I need to change the start and end locations of predictive statement in accordance to descriptive_1 and 3


if line containing PREDICTIVE statement has start locations > descriptive_1 or descriptive_3 start location then i have to replace start location of predictive by descriptive_1 or or descriptive_3
if line containing PREDICTIVE statement has end location < descriptive end .then replace end location of predictive by descriptive1 or descriptive_3
Basically all descriptive locations should fall under all predictive start and end locations.
Another thing to note is thedescriptive statements have same parent as the predictive name)
The end result should look like :

Code:
source1     LEN        predictive    391082  394347  0.955489        +       .       Name=sa000003.1;ID=sa000003;Alias=sa121751.1;
source1     LEN       descriptive_1   391082  392878  .       .       .       Parent=sa000003.1;supp_id=.1805.1;

source1      LEN        predictive    408863  4168533  0.999853        -       .       Name=sa000004.1;ID=sa000004;
source1      LEN        descriptive_1   416523  416853  .       .       .       Parent=sa000004.1;supp_id=14.112.2;

source1     LEN        predictive    347154  351449  0.485927        -       .       Name=sa000006.1;ID=sa000006;Alias=sa121750.;
source1      LEN         descriptive_1   348799  351449  .       .       .       Parent=sa000006.1;supp_id=1800.1;
source1      LEN         descriptive_3   347154  348319  .       .       .       Parent=sa000006.1;supp_id=1800.1;

Smilie

Thanks

Last edited by siya@; 03-06-2014 at 07:17 PM..
# 2  
Old 03-06-2014
What have you and sa@@ tried to solve this problem?
# 3  
Old 03-06-2014
This is the code I tried!
Sorted the file first and then tried to join the contents!

Code:
sort -o file 
join f4a f4b | whille read f4a f4b
do
 if (( ( $f4a <= $f4a'next)
||(  $f4b <= $f4b'next) ))
 then
  echo $f4a $f4a' $f4b $f4b'
 
done

# 4  
Old 03-07-2014
Please explain the logic behind sorting a file named fileand joining two other files named f4a and f4b. How does this help get the minimum value from a field in a group of related lines and get the maximum value from another field in the same group of lines?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Writing to two locations at once

I have a backup script that runs on CRON that I developed about 5 years ago. It has always worked perfectly but a recent firmware update on my QNAP TS 259 has seem to break the large file move/copy capability amongst the ESATA drives. I would like to just change my backhup.sh so that writes... (3 Replies)
Discussion started by: mackconsult
3 Replies

2. UNIX for Advanced & Expert Users

Edit file

Hi All, I have file with 200K Records and each line with 400 character. I need to edit the some part of the file. For example, i need to edit character from 115 to 125, 135to 145 and 344 to 361 Can you please anyone help me to do this? Regards, (1 Reply)
Discussion started by: balasubramani04
1 Replies

3. Shell Programming and Scripting

Inserting commas into file at set locations...

Hey everyone. What would be the best method to insert commas (or comma-quotes) into a file at set locations. Every line in the file looks like this: 1234567890123456 123456BIGAUDIODYNAMITE33 123.12 123456 12345678901234MARK E WILLIAMS 123456 The comma's should... (6 Replies)
Discussion started by: Astrocloud
6 Replies

4. Shell Programming and Scripting

Program to insert Delimiters at fixed locations in a file, Can you please Debug it for me??

Can someone please help?I have a file - fixed.txt----------------------------AABBBBCCCCCCDDDEEFFFFGGGGGGHHHIIJJJJKKKKKKLLL----------------------------To insert delimiters at fixed lengths of 2, 4, 6, 3, I created a file text1.txt as-------------------2463----------------------and trying to execute... (10 Replies)
Discussion started by: jd_mca
10 Replies

5. UNIX for Advanced & Expert Users

Insert Delimiter at fixed locations in a flat file

Hi Can somebody help me with solution for this PLEASE? I have a flat file and need to insert delimiters at fixed positions in all the lines so that I can easily convert into EXCEL with columns defined as per their width. For Example Here is the file { kkjhdhal sdfewss sdtereetyw... (7 Replies)
Discussion started by: jd_mca
7 Replies

6. Shell Programming and Scripting

Sending a file to 24 Server locations parallely

Hi All, I have to send a processed file to 24 different server locations. I feel, if this job can be done parallel in the background - Time will come down. I found the script to FTP the file for a single server location through past Unix posts as below: #!/usr/bin/ksh ftp -v -n... (16 Replies)
Discussion started by: vsmeruga
16 Replies

7. Shell Programming and Scripting

Script to Edit the file content and create new file

I have a requirement, which is as follows *. Folder contains list of xmls. Script has to create new xml files by copying the existing one and renaming it by appending "_pre.xml" at the end. *. Each file has multiple <Name>fileName</Name> entry. The script has to find the first occurance of... (1 Reply)
Discussion started by: sudesh.ach
1 Replies

8. Solaris

file locations...

Hi Guys, There was a post that I saw here a while ago regarding file system layout and what to put where, which I am unable to find now.. A user here posted a man page that list what each partition should have in it and what it is used for and were you should install custom packages. ie:... (1 Reply)
Discussion started by: Tornado
1 Replies

9. Shell Programming and Scripting

Standard Out to Two Locations

Is it possible to redirect standard output to two locations? Unfortunately, I need to redirect it to two different files. Or if there might be any utilities that can do it. I'm suspecting not as it's all pipes and filters, but thought I'd ask. (2 Replies)
Discussion started by: GaryRudolph
2 Replies
Login or Register to Ask a Question