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
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.
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?
I have done some changing files around and it seems that the paste command is only pulling from the second input file. What would cause it to do this? I changed the files around and if the lat was fist and lon was second pulled data from the lon and vice versa.
create file a -- put some junk in there.
create file b -- put some junk in there.
run the command:
paste -d' ' a b > c
exactly like that right before or after your paste command in your script.
if c contains something -- then paste is working as advertised.
If THAT doesn't work.... we'll go to C. By coincidence, I rewrote the
paste command on my system because I wanted something similar
to the output of the Visual SourceSafe diff command.
It has some digits missing from the lat file it should be XXXX.XXXXXX but all of the digits are in the lon file. I wonder what is causing this to happen? Why would it not want to read the first file with a deliminator? I think it is a conspiracy.
Hi, can I just jump in here
as a noob i'd not heard of the paste command, and was quite interested in what it could do. I tried the command as suggested
#paste -d' 'filea fileb > filec and got the same results as the OP, in that only details from the second file were being picked up.
however with a quick blurt at the man page i tried again, with some spaces that were not originally apparent from the suggested post
OK... I am back to work... The last post talking about spaces... I tried but I am still getting the same result... Do spaces matter that much... I know whitespace makes a difference but there has to be a reason why it is not pulling from the second file using the delimiter.
As you can see the spaces do matter, as does the type of quotes, in the above examles i have used the single quotes('), in the following examples, I am using the backquotes (`) and the double quotes (").
I get both files and some of the first has been cut off. So I know it can read the file it just does not want to do it how I want. I am about to let this go and look for a work around on this problem. Is there any other way of doing this?
Thanks also to everyone who has posted help for this issue I appreciate such hospitality from the Unix.com community.
ok.... totally different approach since paste is causing you so much trouble:
#!/bin/ksh
len_a=$( wc -l < a )
len_b=$( wc -l < b )
if [ $len_a -gt $len_b ]; then
max=$len_b
else
max=$len_a
fi
(
head -n $max a
head -n $max b
) | pr -l$max -2