The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
merge text files panchpan AIX 4 12-11-2008 08:34 AM
How to Merge Two .xls files side by side into a single .xls jagadish99 Shell Programming and Scripting 2 09-24-2008 07:44 AM
How to Merge Two .xls files side by side into a single .xls jagadish99 Shell Programming and Scripting 0 08-27-2008 07:38 AM
How to print two sql query outputs side by side in excel prasee Shell Programming and Scripting 6 09-08-2007 03:20 AM
Having a Unix system installed side to side with Windows? Pcslider UNIX for Dummies Questions & Answers 14 01-29-2002 06:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-02-2009
ahinkebein ahinkebein is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 8
Merge 2 text files to one text file side by side

Inquiring minds want to know.... I need to take two files that I have latitude and longitude values and then combine them into one file with the values side by side separated by a space.

the first file is temp113-lat.txt and the second is temp113-lon.txt. They each have values listed in the file like the example below

<temp113-lat.txt>
2644.989500
2645.791200
2647.358600
2647.358300
2647.338700
2647.307900
2647.312100
2647.240400
2647.000300
2646.618800
2646.472100
2646.358800

<temp113-lon.txt>
5104.146495
5103.428400
5103.305700
5103.446300
5103.442100
5103.538900
5103.875200
5104.080100
5105.286800
5105.493300
5105.901000
5106.284000


I want to take these and post them into a .txt file in the following format.

<113latlon.txt>
2644.989500 5104.146495
2645.791200 5103.428400
.... ....

I am trying to write a script to do this automatically but I am missing the line with the command string to do this function. I have tried to use the "paste" command and for some reason it will not output the correct format I want. anyone want to jump in on this one for me... I am at my limit.
  #2 (permalink)  
Old 02-02-2009
quirkasaurus's Avatar
quirkasaurus quirkasaurus is offline
Registered User
  
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 373
paste -d' ' filea fileb > filec

-d specifies the delimiter.
  #3 (permalink)  
Old 02-02-2009
ahinkebein ahinkebein is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 8
That is what I thought. I am not really understanding what the problem is... I did that exact command and this is what I got

[77225 loc]$ paste -d' ' temp113-lat.txt temp113-lon.txt
5105.471900
5105.626300
5104.146495
5104.146495
5104.146495
5103.428400
5103.305700

This is only one of the files and it seperated at the beginning by a space. Why would it only be pulling the data from one file? I checked both files and they contain data. Could it be due to the fact there is a process to get these files? I am including the process in the script.

grep m_lat /113/*.log > /loc/temp113lat.txt
grep m_lon /113/*.log > /loc/temp113lon.txt
grep m_lat /114/*.log > /loc/temp114lat.txt
grep m_lon /114/*.log > /loc/temp114lon.txt
cd /loc
awk '{print $3}' temp113lat.txt > temp113-lat.txt
awk '{print $3}' temp113lon.txt > temp113-lon.txt
awk '{print $3}' temp114lat.txt > temp114-lat.txt
awk '{print $3}' temp114lon.txt > temp114-lon.txt
The next line would be the process to combine the files into one text file so the other program can read them. Any thoughts?
  #4 (permalink)  
Old 02-02-2009
quirkasaurus's Avatar
quirkasaurus quirkasaurus is offline
Registered User
  
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 373
no. it should work. are you sure that temp113-lat.txt has data?

i'd put some diagnostics following the awk scripts...
just /bin/ls -l or wc -l *
  #5 (permalink)  
Old 02-02-2009
ahinkebein ahinkebein is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 8
I checked both of the files and they contain data.... I am really lost on this one...

Could it be the - in the file name?
  #6 (permalink)  
Old 02-02-2009
ahinkebein ahinkebein is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 8
[77225 loc]$ wc -l temp113-lon.txt
52 temp113-lon.txt
[77225 loc]$ wc -l temp113-lat.txt
52 temp113-lat.txt
[77225 loc]$
  #7 (permalink)  
Old 02-02-2009
quirkasaurus's Avatar
quirkasaurus quirkasaurus is offline
Registered User
  
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 373
i might make the file names a little more different just so it's easier to tell what's what.
maybe therein is the problem.

maybe like this:

grep junk some_file > grep_some_file

awk junk grep_some_file > awk_some_file

paste -d' ' awk_some_file awk_some_other_file > paste_some_files



But copying everything you've mentioned -- from the original post -- and
trying it on my system - - - - paste -d' ' worked perfectly.

it looks like ~something~ is nuking that first file argument to the paste command,
or the file name is wrong maybe....
Closed Thread

Bookmarks

Tags
text processing

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0