Replace text in column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace text in column
# 1  
Old 01-03-2011
Replace text in column

Hi:

I have a file as below:

Code:
#LINE 3841.0
        14663859  358272.0  676600.0     20.00   1510.00
                                         91.00   1534.00
                                        215.00   1624.00
                                        374.00   1688.00
        14663899  358772.0  676600.0      3.00   1499.00
                                        226.00   1621.00
                                        380.00   1694.00
                                        589.00   1783.00
#LINE 3842.0
        14663979  359772.0  676600.0     16.00   1505.00
                                        152.00   1566.00
                                        341.00   1666.00
                                        631.00   1796.00
 
        14664019  360272.0  676600.0     16.00   1508.00
                                        141.00   1566.00
                                        338.00   1678.00
                                        601.00   1787.00

I would like to get the output file like this:

Code:
        14663859  358272.0  676600.0     20.00   1510.00
                  358272.0  676600.0     91.00   1534.00
                  358272.0  676600.0    215.00   1624.00
                  358272.0  676600.0    374.00   1688.00
        14663899  358772.0  676600.0      3.00   1499.00
                  358772.0  676600.0    226.00   1621.00
                  358772.0  676600.0    380.00   1694.00
                  358772.0  676600.0    589.00   1783.00
        14663979  359772.0  676600.0     16.00   1505.00
                  359772.0  676600.0    152.00   1566.00
                  359772.0  676600.0    341.00   1666.00
                  359772.0  676600.0    631.00   1796.00
        14664019  360272.0  676600.0     16.00   1508.00
                  360272.0  676600.0    141.00   1566.00
                  360272.0  676600.0    338.00   1678.00
                  360272.0  676600.0    601.00   1787.00
                  360272.0  676600.0    778.00   1855.00

# 2  
Old 01-03-2011
Code:
perl -ne 'next if /#LINE|^\s+$/;
          next if (-z $_); s/ +/\t/g;
          if (/^\s*[\d\.]+(\s+[\d\.]+\s+[\d\.]+\s+)([\d\.]+\s+[\d\.]+\s*)$/)
          {$t=$1; print "$_";}else{s/^\s+//;print "\t\t$t$_"};' inputfile

# 3  
Old 01-03-2011
Code:
awk '/^#/{next}NF>2{p2=$2;p3=$3;print}NF==2{printf "%26s %9s %9s %9s\n",p2,p3,$1,$2}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk script to extract a column, replace one of the header and replace year(from ddmmyy to yyyy)

I have a csv which has lot of columns . I was looking for an awk script which would extract a column twice. for the first occurance the header and data needs to be intact but for the second occurance i want to replace the header name since it a duplicate and extract year value which is in ddmmyy... (10 Replies)
Discussion started by: Kunalcurious
10 Replies

2. Shell Programming and Scripting

Get extract and replace column with link in a column where it exists

hi i have sample data a,b,c,d,e,g h http://mysite.xyx z,b,d,f,e,s t http://123124# a,b,c,i,m,nothing d,i,j,e,w,nothing output expected is a,b,c,d,e,http://mysite.xyx z,b,d,f,e,http://123124# a,b,c,i,m,nothing d,i,j,e,w,nothing i can get only links using grep -o 'http.*' i... (8 Replies)
Discussion started by: zozoo
8 Replies

3. Shell Programming and Scripting

Replace column that matches specific pattern, with column data from another file

Can anyone please help with this? I have 2 files as given below. If 2nd column of file1 has pattern foo1@a, find the matching 1st column in file2 & replace 2nd column of file1 with file2's value. file1 abc_1 foo1@a .... abc_1 soo2@a ... def_2 soo2@a .... def_2 foo1@a ........ (7 Replies)
Discussion started by: prashali
7 Replies

4. UNIX for Dummies Questions & Answers

Use sed to replace but only in a specific column of the text file

Hi, I would like to use sed to replace NA to x ('s/NA/x/g'), but only in the 5th column of the space delimited text file, nowhere else. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

Replace a text with a particular column and particular line

I have a file test.txt cat test.txt shows 10 200 5 600 1000 4 88 9 3 6 66 101 Suppose, I want to replace a number with a particular line and column. For instance, the number 88 in line 3, column 2. I want to replace it by 99. How can I do that? Note that I am... (11 Replies)
Discussion started by: hbar
11 Replies

6. UNIX for Dummies Questions & Answers

Replacing a specific column of a text file with another column

I have a text file in the following format: 13412 NA06985 0 0 2 46.6432798439 4 4 4 4 13412 NA06991 NA06993 NA06985 2 48.8478948517 4 4 2 4 13412 NA06993 0 0 1 45.8022601455 4 4 2 4 13401 NA06994 0 0 1 48.780669145 4 4 4 4 13401 NA07000 0 0 2 47.7312017846 2 4 4 4 13402 NA07019... (3 Replies)
Discussion started by: evelibertine
3 Replies

7. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

8. Shell Programming and Scripting

Replace text based on column

Replace these if the column is - p = q q = p r = s s = r input - PQRSSP + PQRS output - QPSRRQ + PQRS Some thing,like (5 Replies)
Discussion started by: bumblebee_2010
5 Replies

9. Shell Programming and Scripting

awk/sed column replace using column header - help

$ cat log.txt Name Age Sex Lcation nfld alias xsd CC 25 M XYZ asx KK Y BB 21 F XAS awe SS N SD 21 M AQW rty SD A How can I replace the column with header "Lcation" with the column with header "alias" and delete the "alias" column? so that the final output will become: Name Age Sex... (10 Replies)
Discussion started by: jkl_jkl
10 Replies

10. Shell Programming and Scripting

Replace 10th column with a new column--- Terriblly hurry

Hi Can any one tell me how to replace the 10th column in a file(comma delimted) with a new file with a single column. Can any one Help me out of the please as soon as possible as i am in a terribley hurry!!!!!! Many THanks, (2 Replies)
Discussion started by: ahmedwaseem2000
2 Replies
Login or Register to Ask a Question