LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-17-2009, 01:29 PM   #1
ml41782
LQ Newbie
 
Registered: May 2009
Posts: 14

Rep: Reputation: 0
Unhappy Creating a singe line entry from data from multiple other sources


I have been mullying over this all morning and I'm sure there is a simple answer.

I'm trying to create a single string of data and send it out over a serial port for ham radio. I'm pulling my data in from a weather system and formatting the data to match the example. however I end up with 9 lines in the final file instead of one single line.

Where did I go wrong ?

!/bin/bash
#
# Creation of the APRS
# Weather sentence
#
# created 17 June 2009
#
# :@233011z3811.20NS07746.00W_(windDir.csv)'/'(windspeed.csv)g000t(temperature.csv)r000P000p000h00b00000/Spotsylvania, Va
#
echo ":@" > aprs.txt
date -u +%k%M%S >> aprs.txt
cat location.txt >> aprs.txt
cat /var/www/winddir-t.csv >> aprs.txt
echo "/" >> aprs.txt
cat /var/www/windspeed-t.csv >> aprs.txt
echo "g000t" >> aprs.txt
cat /var/www/temperature-t.csv >> aprs.txt
cat fillin.txt >> aprs.txt
 
Old 06-17-2009, 01:39 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You have to avoid the newline. Use the option -n of echo and pass any command trough that:
Code:
echo -n ":@" > aprs.txt
echo -n $(date -u +%k%M%S) >> aprs.txt
echo -n $(cat location.txt) >> aprs.txt
echo -n $(cat /var/www/winddir-t.csv) >> aprs.txt
echo -n "/" >> aprs.txt
echo -n $(cat /var/www/windspeed-t.csv) >> aprs.txt
echo -n "g000t" >> aprs.txt
echo -n $(cat /var/www/temperature-t.csv) >> aprs.txt
echo -n $(cat fillin.txt) >> aprs.txt
 
Old 06-21-2009, 10:38 AM   #3
ml41782
LQ Newbie
 
Registered: May 2009
Posts: 14

Original Poster
Rep: Reputation: 0
Unhappy setting a string length to alway be X charactors long

I'm trying to create a string for weather system. The string requirements are for three spaces for each of the values. Unless it is in this format it will fail.
currently I'm adding in 1 extra zero in the code. but if the value is less than 10 i.e. wind then I end up with a 2 digit number and a failure.

:@135004z3811.22N/07746.12W_45/00g000t073r001P001p080h00b00000/

:@135004z3811.22N/07746.12W_045/000g000t073r001P001p080h00b00000/

Thank you for the help in advance

Mike
 
Old 06-21-2009, 10:45 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
You need to tell us more about where you are getting the data, what code you are using, etc.

I have a hunch that you might want the "printf" function----to print a value in a specified format.
 
Old 06-21-2009, 11:17 AM   #5
ml41782
LQ Newbie
 
Registered: May 2009
Posts: 14

Original Poster
Rep: Reputation: 0
I'm sorry about that.

The data files are CSV.
here is the bash file
#!/bin/bash
# Weather data stream created 17 June 2009
# Push data to the RF side and to the internet side
# aprs.sh
#
echo -n "xastir_udp_client localhost 2023 k4mqf-9 0000 -to_rf " > aprs2.sh
echo -n "xastir_udp_client localhost 2023 k4mqf-9 0000 -to_inet " > aprs3.sh
#
echo -n $(cat q.txt) >> aprs2.sh
echo -n $(cat q.txt) >> aprs3.sh
echo -n " K4MQF-9>APX194,WIDE2-2:@" >> aprs2.sh
echo -n " K4MQF-9>APX194,WIDE2-2:@" >> aprs3.sh
echo -n $(date -u +%H%M%S) >> aprs2.sh
echo -n $(date -u +%H%M%S) >> aprs3.sh
echo -n "z3811.22N/07746.12W_" >> aprs2.sh
echo -n "z3811.22N/07746.12W_" >> aprs3.sh
echo -n $(cat /var/www/winddir-ta.csv) >> aprs2.sh
echo -n $(cat /var/www/winddir-ta.csv) >> aprs3.sh
echo -n "/0" >> aprs2.sh
echo -n "/0" >> aprs3.sh
echo -n $(cat /var/www/windspeed-ta.csv) >> aprs2.sh
echo -n $(cat /var/www/windspeed-ta.csv) >> aprs3.sh
echo -n "g000t0" >> aprs2.sh
echo -n "g000t0" >> aprs3.sh
echo -n $(cat /var/www/temperature-ta.csv) >> aprs2.sh
echo -n $(cat /var/www/temperature-ta.csv) >> aprs3.sh
echo -n "r000P001p001h00b00000/Spotsylvania, Va " >> aprs2.sh
echo -n "r000P001p001h00b00000/Spotsylvania, Va " >> aprs3.sh
echo -n $(cat q.txt) >> aprs2.sh
echo -n $(cat q.txt) >> aprs3.sh

otg1017@Webserver:~$ cat /var/www/windspeed-ta.csv
0

otg1017@Webserver:~$ cat /var/www/winddir-ta.csv
45

otg1017@Webserver:~$ cat /var/www/temperature-ta.csv
73
 
Old 06-21-2009, 01:40 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
I took the liberty to merge your two closely related threads.



Cheers,
Tink
 
Old 06-21-2009, 01:47 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Try changing
Code:
echo -n $(cat /var/www/winddir-ta.csv) >> aprs2.sh
to
Code:
echo -n $( printf  "%.3d" $(cat /var/www/winddir-ta.csv) ) >> aprs2.sh

Cheers,
Tink
 
Old 06-21-2009, 02:12 PM   #8
ml41782
LQ Newbie
 
Registered: May 2009
Posts: 14

Original Poster
Rep: Reputation: 0
I think I have figured it out. Unles there is a cleaner answer

Thank you

# Weather data stream created 17 June 2009
# Push data to the RF side and to the internet side
#
echo -n "xastir_udp_client localhost 2023 k4mqf-9 13191 -to_rf " > aprs2.sh
echo -n "xastir_udp_client localhost 2023 k4mqf-9 13191 -to_inet " > aprs3.sh
#
echo -n $(cat q.txt) >> aprs2.sh
echo -n $(cat q.txt) >> aprs3.sh
echo -n "K4MQF-9>APX194,WIDE2-2:@" >> aprs2.sh
echo -n "K4MQF-9>APX194,WIDE2-2:@" >> aprs3.sh
echo -n $(date -u +%H%M%S) >> aprs2.sh
echo -n $(date -u +%H%M%S) >> aprs3.sh
echo -n "z3811.22N/07746.12W_" >> aprs2.sh
echo -n "z3811.22N/07746.12W_" >> aprs3.sh
awk '{ for (i=1; i<=NF; i++) $i=sprintf("%03d", $i); print; }' /var/www/winddir-ta.csv > /var/www/winddir-tb.csv

echo -n $(cat /var/www/winddir-tb.csv) >> aprs2.sh
echo -n $(cat /var/www/winddir-tb.csv) >> aprs3.sh
echo -n "/" >> aprs2.sh
echo -n "/" >> aprs3.sh
awk '{ for (i=1; i<=NF; i++) $i=sprintf("%03d", $i); print; }' /var/www/windspeed-ta.csv > /var/www/windspd-tb.csv

echo -n $(cat /var/www/windspd-tb.csv) >> aprs2.sh
echo -n $(cat /var/www/windspd-tb.csv) >> aprs3.sh
echo -n "g000t" >> aprs2.sh
echo -n "g000t" >> aprs3.sh
awk '{ for (i=1; i<=NF; i++) $i=sprintf("%03d", $i); print; }' /var/www/temperature-ta.csv > /var/www/temp-tb.csv

echo -n $(cat /var/www/temp-tb.csv) >> aprs2.sh
echo -n $(cat /var/www/temp-tb.csv) >> aprs3.sh
echo -n "r000P000p000h00b00000/Spotsylvania, Va " >> aprs2.sh
echo -n "r000P000p000h00b00000/Spotsylvania, Va " >> aprs3.sh
echo -n $(cat q.txt) >> aprs2.sh
echo -n $(cat q.txt) >> aprs3.sh

output was ::
2009-06-21 12:03:36 UTC: K4MQF-9>APX194,K4MQF-2,N3HF-1,WIDE2*,qAS,WC4J:@175404z3811.22N/07746.12W_45/00g000t73r000P000p000h00b00000/Spotsylvania, Va

output now ::
2009-06-21 17:57:36 UTC: K4MQF-9>APX194,K4MQF-2,N3HF-1,WIDE2*,qAS,WC4J:@175404z3811.22N/07746.12W_045/000g000t073r000P000p000h00b00000/Spotsylvania, Va

Last edited by ml41782; 06-21-2009 at 02:14 PM.
 
Old 06-21-2009, 02:17 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hmmm ... given the previous output-lines I assumed there's only
one value in the .csv ... so the iteration over the NF is a waste
of time, but I may have understood the whole thing wrong.

And while I'm a big fan of awk I feel it's overkill in this
context ;] My solution will do just fine. :D


Cheers,
Tink

Last edited by Tinkster; 06-21-2009 at 02:18 PM.
 
Old 06-21-2009, 02:28 PM   #10
ml41782
LQ Newbie
 
Registered: May 2009
Posts: 14

Original Poster
Rep: Reputation: 0
I tried your code fix versus mine.

I liked your alot cleaner and eaier to read,

Thanks

Mike
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
have a Variable with multiple lines of data need to have it all on one line seperated xskycamefalling Programming 11 05-12-2009 05:44 AM
data type help needed and multiple inputs in single line shank.nikhil Programming 3 04-04-2009 09:04 PM
rm-command in singe Shot??? ajeetraina Linux - Newbie 1 12-28-2007 01:44 AM
sed/awk/grep for multiple line data hotrodmacman Programming 8 10-18-2007 12:06 PM
sources.list entry format for suse 9.2.9 repository TomF SUSE / openSUSE 4 04-06-2005 05:49 PM


All times are GMT -5. The time now is 06:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration