Need script to merge two spreadsheets


 
Thread Tools Search this Thread
# 15  
Are you sure your files were in Unix format? Your output file is in DOS format. What OS are you using and what version?
# 16  
Quote:
Originally Posted by Scrutinizer
Are you sure your files were in Unix format? Your output file is in DOS format. What OS are you using and what version?
Maybe I'm not so sure now. I've never had a problem with formats before. I'm making and viewing all my files in Microsoft excel under Windows 7, saving them as tab-delimited .txt files. I do see an option to save in a DOS format but I've never used that.

My unix environment is run through VMware fusion - Ubuntu v11.10.
# 17  
When you transfer those txt files from Windows to Ubuntu, you need to convert them to unix format either during transfer or after transfer. If after transfer, you can convert the file to unix like so:
Code:
fromdos file

or
Code:
tr -d '\r' < file > newfile

# 18  
Quote:
Originally Posted by Scrutinizer
When you transfer those txt files from Windows to Ubuntu, you need to convert them to unix format either during transfer or after transfer. If after transfer, you can convert the file to unix like so:
Code:
fromdos file

or
Code:
tr -d '\r' < file > newfile


Bingo! Thanks a lot!

How can I make the code a .awk script that I can make an executable? And can be called with:

PHP Code:
$awk code.awk file1 file2 

Last edited by torchij; 05-03-2012 at 03:14 PM..
# 19  
Try this:
Code:
cat code.awk 
BEGIN{
  FS=OFS="\t"
}

{ 
  print
}

NR==1{
  getline < secondfile
  for (i=2;i<=NF;i++) Label[$i]=i
  for (i=2;i<=NF;i++) Order[i]=Label[$i]
  next
} 

{
  getline < secondfile
  $1=""
  split($0,Field)
  for(i=2;i<=NF;i++) $Order[i]=Field[i]
  print
}

$ awk -f code.awk secondfile=file2.txt file1.txt

or try this:
Code:
$ cat code2
#!/bin/sh
[ $# -eq 2 ] || { echo "Usage: ${0##*/} file1 file2" >&2; exit 1 ;}

awk '
BEGIN{
  FS=OFS="\t"
}

{ 
  print
}

NR==1{
  getline < secondfile
  for (i=2;i<=NF;i++) Label[$i]=i
  for (i=2;i<=NF;i++) Order[i]=Label[$i]
  next
} 

{
  getline < secondfile
  $1=""
  split($0,Field)
  for(i=2;i<=NF;i++) $Order[i]=Field[i]
  print
}
' secondfile="$2" "$1"

$ ./code2 file1.txt file2.txt

# 20  
Perfect!!
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Gadgets
Difficulty: Medium
The Western Electric Model 500 telephone uses tone dialing to dial phone numbers.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to merge and delete lines

POLY_STATS { EqName 103_tri Id 123 act_polyCount 1 act_polyValue 0 } POLY_STATS { EqName 103_tri Id 123 pass_polyCount 2 pass_polyValue 0 } POLY_STATS { EqName 103 Id 123 mes_polyCount 2 mes_polyValue 0 (5 Replies)
Discussion started by: Jag02
5 Replies

2. Shell Programming and Scripting

How to merge Expect script inside shell script?

Hi I have two scripts one is Expect and other is shell. I want to merge Expect code in to Shell script so that i can run it using only one script. Can somebody help me out ? Order to execute: Run Expect_install.sh first and then when installation completes run runTests.sh shell script. ... (1 Reply)
Discussion started by: ashish_neekhra
1 Replies

3. Shell Programming and Scripting

script to merge two files on an index

I have a need to merge two files on the value of an index column. input file 1 id filePath MDL_NUMBER 1 MFCD00008104.mol MFCD00008104 2 MFCD00012849.mol MFCD00012849 3 MFCD00037597.mol MFCD00037597 4 MFCD00064558.mol MFCD00064558 5 MFCD00064559.mol MFCD00064559 input file 2 ... (9 Replies)
Discussion started by: LMHmedchem
9 Replies

4. Shell Programming and Scripting

Help with merge Shell Script

I have a file test.log The content of the file is : a:R_yz:1 a:R_cd:2 a:F_bc:0 a:F_xx:3 b:R_dg:5 b:R_gf:1 b:F_fd:4 I want the output is : :a R_yz 1 3 3 : R_cd 2 : F_bc 0 : F_xx 3 :b R_dg 5 6 4 : R_gf 1 : F_fd 4 (8 Replies)
Discussion started by: mnmonu
8 Replies

5. Shell Programming and Scripting

script to merge multiple line

Dear all, I am new to this community. I need a script that will merge two lines of a text file based on some character. for example- Input asfdas fas sdfhksd sdf ss 45 gf# gjsdh fhjsd yiu oiuio ioioiuii sdgjdshsdg sdhfjk sdfhsd sdf sdf sdf wer wer we# qqwewq qwe qwe wer# fsdf sdf... (8 Replies)
Discussion started by: wildhorse
8 Replies

6. Shell Programming and Scripting

merge two files via looping script

Hi all, I hope you can help me. I got a file a and a file b File a contains a b c d e f g h File b contains 1 2 3 (8 Replies)
Discussion started by: stinkefisch
8 Replies

7. Shell Programming and Scripting

script to merge xml files with options

Hi, I have a very basic knowledge of shell scripting & would like some help with a little problem I have. I sometimes use a program calle phronix & sometimes like to compare its results which are *.xml files. Which is easy enough but a friend wants to avoid typing the path to the files.... (2 Replies)
Discussion started by: ptrbee
2 Replies

8. Shell Programming and Scripting

script needed to merge two files and report differences

Hello, I have two txt files that look like this: db.0.0.0.0: Total number of NS records = 1 db.127.0.0.0: Total number of NS records = 1 Total number of PTR records = 1 db.172.19.0.0: Total number of NS records = 1 Total number of PTR records = 3 db.172.19.59.0: Total... (8 Replies)
Discussion started by: richsark
8 Replies

9. Shell Programming and Scripting

Merge two files in windows using perl script

Hi I want to merge two or more files using perl in windows only(Just like Paste command in Unix script) . How can i do this.Is ther any single command to do this? Thanks Kunal (1 Reply)
Discussion started by: kunal_dixit
1 Replies

10. Shell Programming and Scripting

shell script to merge files

Can anybody help me out with this problem " a shell program that takes one or any number of file names as input; sorts the lines of each file in ascending order and displays the non blank lines of each sorted file and merge them as one combined sorted file. The program generates an error... (1 Reply)
Discussion started by: arya
1 Replies

Featured Tech Videos