Sponsored Content
Top Forums Shell Programming and Scripting Replace specific columns in one file with columns in another file Post 302479077 by Chubler_XL on Thursday 9th of December 2010 06:10:38 PM
Old 12-09-2010
Not sure about the format of these .dilm files, but here is an awk script that works on space/tab seperated files.
If you can post an example of the .dilm files, I'll try and update it to work with them.

Code:
$ cat file1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 
$ cat file2
one two three four five six seven eight nine ten eleven twelve thirteen fourteen
ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE TEN ELEVEN TWELVE THIRTEEN FOURTEEN
 
$ cat mehdib.awk
awk -v "D=$1" -v "S=$2" '
   BEGIN {
       split(D,DA, ",");
       split(S,SA, ",");
   }
   FNR==NR {
      for(P in SA) A[NR]=A[NR]$SA[P]FS; next }
   { i=1; 
     split(A[FNR], NEW, FS);
     for(P in DA) $DA[P]=NEW[i++] }
   1 ' file2 file1
 
$ ./mehdib.awk 2,6,16 2,3,1
1 two 3 4 5 three 7 8 9 10 11 12 13 14 15 one 17 18 19 20
1 TWO 3 4 5 THREE 7 8 9 10 11 12 13 14 15 ONE 17 18 19 20


Last edited by Chubler_XL; 12-09-2010 at 07:33 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting specific columns from a file

Hi Friends, I want to delete specific columns from a file. Say my file content is as follows: "1","a","ww1",1234" "2","b","wwr3","2222" "3","c","erre","3333" Now i want to delete the column 2 and 4 from this file. That is I want the file content to be: "1","ww1" "2","wwr3"... (11 Replies)
Discussion started by: premar
11 Replies

2. Shell Programming and Scripting

How can i replace certain columns in the file

Can i use sed command to replace certain column in the file let say i hav D1254215221542 MANA3DS2OOR454 C1254815221121 MDGA4GH4OOR454 A1254215221522 AFFA4DF4OODS54 S3454815221121 TDTA4GH465R454 I wanted to change only at postition 21 and 22 which is DS,GH,DF and GH i want find that if... (6 Replies)
Discussion started by: mani_um
6 Replies

3. Shell Programming and Scripting

Replace specific columns

hi All, Thi sis very urgent. I have large files with pipe delimited. For example: 1.txt 1001024|120|9|-0.0|#| 1001025|120|9|#| 1001026|120|9|#| 1001032|120|2|-0.0|#| 1002026|110|9|#| 1002027|110|9|-0.0|#| 1002028|120|1|1.0|#| I need to replace the 4th filed if it is # by |-| my... (2 Replies)
Discussion started by: jisha
2 Replies

4. UNIX for Dummies Questions & Answers

Displaying specific columns in a file

Hi, I'm just wondering how you display a specific set of columns of a specified file in Unix. For example, if you had an AddressBook file that stores the Names, Phone numbers, and Addresses of people the user entered in the following format (the numbers are just to give an idea of what column... (1 Reply)
Discussion started by: logorob
1 Replies

5. UNIX for Dummies Questions & Answers

Switch and replace columns in a file

HP-UX I have a fixed length file like this 9921190625797AE2560 20091001US20091001@@NEWSITE @@ 20091013001X X 01NEW00DNA00007081 @@ SPRINGFIELD @@ ... (2 Replies)
Discussion started by: rs1969
2 Replies

6. Shell Programming and Scripting

Replace columns of one file into another

Hi, I have two files that are different in size (column #'s differ). Each file has the exact same 3 starting columns. File 1 has 240 columns while File 2 has 45 columns. So if the first 3 columns are the same, I want to replace columns 83 to 163 from File 1 with columns 18 to 33 from File... (7 Replies)
Discussion started by: kylle345
7 Replies

7. Shell Programming and Scripting

Transpose whole file and specific columns

Hi, I have a file like this a b c d e f g h i j k l Case1: I want to transpose the whole file Output1 a d g j b e h k c f i l Case2 Transpose a specific column - Say 3rd (6 Replies)
Discussion started by: jacobs.smith
6 Replies

8. Shell Programming and Scripting

Replace text in column1 of a file matching columns of another file

Hi all, I have 2 files: species-names.txt Abaca-bunchy-top-virus ((((Abaca-bunchy-top-virus((Babuvirus((Unassigned((Nanoviridae((Unassigned)))) Abutilon-mosaic-virus ((((Abutilon-mosaic-virus((Begomovirus((Unassigned((Geminiviridae((Unassigned))))... (2 Replies)
Discussion started by: thienxho
2 Replies

9. Shell Programming and Scripting

Need specific columns in a log file as excel.

Hi All... I am in need of few columns from a log file.. in .xls file... below is what i have tried. my log file has 16 colums with " ; " as delimiter, but i need randomn columns 1 2 3 4 5 6 10 11 16 in an excel. I tried to awk the columns with delimiter ; and it worked, below is the log... (5 Replies)
Discussion started by: nanz143
5 Replies

10. Shell Programming and Scripting

Parsing a file and pulling out specific columns

Hi, I am having some difficulty pulling out specific columns using awk. I think what I am doing is iterating through the various columns looking for a match and asking awk to print if a match is found. Here are a few lines from my input: NC_015011.2 Gnomon gene 18691 26481 . ... (1 Reply)
Discussion started by: bioBob
1 Replies
DIFF3(1)						      General Commands Manual							  DIFF3(1)

NAME
diff3 - 3-way differential file comparison SYNOPSIS
diff3 [ -exEX3 ] file1 file2 file3 DESCRIPTION
Diff3 compares three versions of a file, and publishes disagreeing ranges of text flagged with these codes: ==== all three files differ ====1 file1 is different ====2 file2 is different ====3 file3 is different The type of change suffered in converting a given range of a given file to some other is indicated in one of these ways: f : n1 a Text is to be appended after line number n1 in file f, where f = 1, 2, or 3. f : n1 , n2 c Text is to be changed in the range line n1 to line n2. If n1 = n2, the range may be abbreviated to n1. The original contents of the range follows immediately after a c indication. When the contents of two files are identical, the contents of the lower-numbered file is suppressed. Under the -e option, diff3 publishes a script for the editor ed that will incorporate into file1 all changes between file2 and file3, i.e. the changes that normally would be flagged ==== and ====3. Option -x (-3) produces a script to incorporate only changes flagged ==== (====3). The following command will apply the resulting script to `file1'. (cat script; echo '1,$p') | ed - file1 The -E and -X are similar to -e and -x, respectively, but treat overlapping changes (i.e., changes that would be flagged with ==== in the normal listing) differently. The overlapping lines from both files will be inserted by the edit script, bracketed by "<<<<<<" and ">>>>>>" lines. For example, suppose lines 7-8 are changed in both file1 and file2. Applying the edit script generated by the command "diff3 -E file1 file2 file3" to file1 results in the file: lines 1-6 of file1 <<<<<<< file1 lines 7-8 of file1 ======= lines 7-8 of file3 >>>>>>> file3 rest of file1 The -E option is used by RCS merge(1) to insure that overlapping changes in the merged files are preserved and brought to someone's atten- tion. FILES
/tmp/d3????? /usr/libexec/diff3 SEE ALSO
diff(1) BUGS
Text lines that consist of a single `.' will defeat -e. 7th Edition October 21, 1996 DIFF3(1)
All times are GMT -4. The time now is 03:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy