edit and add line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting edit and add line
# 1  
Old 12-30-2010
edit and add line

dear all,

i need your help to change this input to output
Code:
M9_3D_H10__Dflt
->SP_M9N_S
         497224.3125        1598028.1250
         497063.2813        1598002.7500
         496953.1250        1597951.8750
         497122.6250        1597985.7500
         497190.4375        1597994.2500
         497224.3125        1598028.1250
->SP_M9N_S
         496376.8125        1599172.2500
         496554.7813        1599282.5000
         496775.1563        1599426.6250
         496978.5625        1599536.7500
         497207.3750        1599621.5000
         497080.2500        1599536.7500
         496868.3750        1599426.6250
         496724.2813        1599341.8750
         496554.7813        1599240.1250
         496376.8125        1599172.2500
->M9_NCL_NW_060
         513852.5938        1561579.3750
         513288.5313        1561274.5000
         512846.4688        1561091.5000
         512404.3750        1560908.6250
         511992.7813        1560725.6250
         511581.1563        1560573.2500
         511947.0000        1560817.1250
         512206.1563        1560893.3750
         512648.2500        1561122.0000
         513136.0625        1561320.2500
         513091.9375        1561432.2500
         513439.3438        1561613.5000
         513469.5313        1561492.6250
         513623.9063        1561548.8750
         514050.7500        1561747.0000
         514491.9688        1561953.2500
         514850.9375        1562197.3750
         515138.1875        1562340.8750
         515411.0313        1562498.8750
         515123.8125        1562269.1250
         514822.2500        1562068.1250
         514520.6563        1561867.0000
         514276.5625        1561737.7500
         514018.0625        1561622.8750
         513852.5938        1561579.3750


and this output;
Code:
PROFILE SP_M9N_S
     497224.3125   1598028.1250    0                   0.0                          eribudi_nirranda
     497063.2813   1598002.7500    0                   0.0                          eribudi_nirranda
     496953.1250   1597951.8750    0                   0.0                          eribudi_nirranda
     497122.6250   1597985.7500    0                   0.0                          eribudi_nirranda
     497190.4375   1597994.2500    0                   0.0                          eribudi_nirranda
     497224.3125   1598028.1250    0                   0.0                          eribudi_nirranda
EOD
PROFILE SP_M9N_S
     496376.8125   1599172.2500    0                   0.0                          eribudi_nirranda
     496554.7813   1599282.5000    0                   0.0                          eribudi_nirranda
     496775.1563   1599426.6250    0                   0.0                          eribudi_nirranda
     496978.5625   1599536.7500    0                   0.0                          eribudi_nirranda
     497207.3750   1599621.5000    0                   0.0                          eribudi_nirranda
     497080.2500   1599536.7500    0                   0.0                          eribudi_nirranda
     496868.3750   1599426.6250    0                   0.0                          eribudi_nirranda
     496724.2813   1599341.8750    0                   0.0                          eribudi_nirranda
     496554.7813   1599240.1250    0                   0.0                          eribudi_nirranda
     496376.8125   1599172.2500    0                   0.0                          eribudi_nirranda
EOD
PROFILE M9_NCL_NW_060
     513852.5938   1561579.3750    0                   0.0                          eribudi_nirranda
     513288.5313   1561274.5000    0                   0.0                          eribudi_nirranda
     512846.4688   1561091.5000    0                   0.0                          eribudi_nirranda
     512404.3750   1560908.6250    0                   0.0                          eribudi_nirranda
     511992.7813   1560725.6250    0                   0.0                          eribudi_nirranda
     511581.1563   1560573.2500    0                   0.0                          eribudi_nirranda
     511947.0000   1560817.1250    0                   0.0                          eribudi_nirranda
     512206.1563   1560893.3750    0                   0.0                          eribudi_nirranda
     512648.2500   1561122.0000    0                   0.0                          eribudi_nirranda
     513136.0625   1561320.2500    0                   0.0                          eribudi_nirranda
     513091.9375   1561432.2500    0                   0.0                          eribudi_nirranda
     513439.3438   1561613.5000    0                   0.0                          eribudi_nirranda
     513469.5313   1561492.6250    0                   0.0                          eribudi_nirranda
     513623.9063   1561548.8750    0                   0.0                          eribudi_nirranda
     514050.7500   1561747.0000    0                   0.0                          eribudi_nirranda
     514491.9688   1561953.2500    0                   0.0                          eribudi_nirranda
     514850.9375   1562197.3750    0                   0.0                          eribudi_nirranda
     515138.1875   1562340.8750    0                   0.0                          eribudi_nirranda
     515411.0313   1562498.8750    0                   0.0                          eribudi_nirranda
     515123.8125   1562269.1250    0                   0.0                          eribudi_nirranda
     514822.2500   1562068.1250    0                   0.0                          eribudi_nirranda
     514520.6563   1561867.0000    0                   0.0                          eribudi_nirranda
     514276.5625   1561737.7500    0                   0.0                          eribudi_nirranda
     514018.0625   1561622.8750    0                   0.0                          eribudi_nirranda
     513852.5938   1561579.3750    0                   0.0                          eribudi_nirranda
EOD

thanks all


Moderator's Comments:
Mod Comment Please use code tags when posting data and code samples, thank you.

Last edited by Franklin52; 12-31-2010 at 07:19 AM..
# 2  
Old 12-31-2010
Code:
awk '/->/{sub(/->/,"EOD\nPROFILE ")}NR>1{$0=$0 " 0\t0.0\teribudi_nirranda"}END{print "EOD"}1' infile |sed -n '3,$'p


Last edited by rdcwayx; 01-03-2011 at 01:48 AM..
# 3  
Old 01-02-2011
MySQL

sed is more funny Smilie

Code:
# justdoit inputfile

Code:
## justdoit ##
#!/bin/bash

sed '/->/{;=}' "$1" | sed '/^[0-9][0-9]*$/N;s/\([0-9][0-9]*\)\n\(->.*\)/\1 \2/' >tmpSEDx
IFS=$'\n' ;sedarr=($(sed -n '/->/p' tmpSEDx) )

x=0;c=${#sedarr[@]} ; rm -f results
while [ $(( c -=1 )) -gt 0 ] ; do
sed -n "/${sedarr[x]}/,/${sedarr[x+1]}/{;/${sedarr[x+1]}/!p;}" tmpSEDx | sed '1!s/.*/& 0 0.0 eribudi_nirranda/;$ a\EOD' >>results
((x++)) ; done

sed -n "/${sedarr[${#sedarr[*]}-1]}/,/<#>/{;/$/p;}" tmpSEDx | sed '1!s/.*/& 0 0.0 eribudi_nirranda/;$ a\EOD' >>results
sed -i 's/.*->\(.*\)/PROFILE \1/' results ;
more results

Regards
ygemici
# 4  
Old 01-02-2011
Code:
sed '1d;/^-/{s/->/PROFILE /;2!s/^/EOD\n/;};/^[ \t]*[0-9]/{s/$/  0  0.0  eribudi_nirranda/;$s/$/\nEOD/;}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Edit first line of a text file

Hi friends, Issue1: I have a text file with the first line like this #chrom start end Readcount_A Normalized_Readcount_A ReadcountB Normalized_Readcount_B Fc_A_vs_B pvalue_A_vs_B FDR_A_vs_B Fc_B_vs_A pvalue_B_vs_A FDR_B_vs_A <a href="http://unix.com/">Link</a> How can I change it to the... (11 Replies)
Discussion started by: jacobs.smith
11 Replies

2. Shell Programming and Scripting

Edit a Huge one line file

We have a huge file which has just one really large line; about 500 MB. I want to 1. Count all the occurrences of a phrase 2. Replace the phrase with another. Trying to open it using vi has not helped as it complains that it is too large. Can any script help? Please advise. Thank you, (12 Replies)
Discussion started by: kaushikadya
12 Replies

3. Shell Programming and Scripting

up down arrow key and edit on command line.

I am using ksh, By doing change in .profile as set -o vi my updown and history does not work. Also I can not edit command line on prompt using vi command. My TERM is vt100. What is wrong here ? Thanks. :cool: (3 Replies)
Discussion started by: ekb
3 Replies

4. Shell Programming and Scripting

how to edit a content of a document to add \n after each ;

Hi: I'm trying to write a script that reformats a given document (edit the content of a given document) , I want to add a new line \n after each ; in the document. Regards (6 Replies)
Discussion started by: miss_dodi
6 Replies

5. Shell Programming and Scripting

How to edit file to have one line entry?

Hello All, My file content is: DROP TABLE "FACT_WORLD"; CREATE TABLE "FACT_WORLD" ( "AR_ID" INTEGER NOT NULL, "ORG_ID" INTEGER NOT NULL ) DATA CAPTURE NONE COMPRESS YES; I want to change this file to have entries in one... (6 Replies)
Discussion started by: akash2508
6 Replies

6. Shell Programming and Scripting

Edit file content at the specific line.

How to edit file content at the specific line? For example at below The things to edit --> This is line 2. And it is below line 1. This is line 1. This is line 2. # i want to append some words at this row line. How? This is line 3. (8 Replies)
Discussion started by: alvin0618
8 Replies

7. Shell Programming and Scripting

edit a line for getting inputs

Hello Everybody, I have a file with data like this 8z:1 15y:0 7x:0 12w:1 ... ... I would like read each line through a loop and will needing to get the input from each line like this For 8z:1; a=8,b=1 15y:0; a=15,b=0 7x:0; a=7,b=0 Please let me know of a way to... (5 Replies)
Discussion started by: leo.maveriick
5 Replies

8. Shell Programming and Scripting

Edit number of lines in a file to single line

Greetings, I have a file: hostnames.txt which has - # cat hostnames.txt machine1 machine2 I need the output to be saved to a variable as: HOSTNAMELIST=machine1,machine2 Please advise. Thanks, Chiru (3 Replies)
Discussion started by: chiru_h
3 Replies

9. Shell Programming and Scripting

Edit a line in a file with perl

Hi, How can I edit a line in a file? For example, a.txt contains: start: 1 2 3 4 stop: a b c d and I want to change "3" to "9" and to add "5" after "4" the result should be (a.txt): start: 1 9 3 4 5 stop: a b c d Thanks, zed (5 Replies)
Discussion started by: zed
5 Replies

10. UNIX for Dummies Questions & Answers

edit each line in the file

I am trying to edit each line in a file. The file has several columns delimitted by '|'. I need to take out the last two columns. Each line starts with a unique word through which I am storing the lines in a variable and cutting the last two colums. But, when I am echoing the line, it is... (2 Replies)
Discussion started by: chiru_h
2 Replies
Login or Register to Ask a Question