LinuxQuestions.org
Review your favorite Linux distribution.
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 01-21-2003, 07:50 PM   #1
beedyrazzle
LQ Newbie
 
Registered: Sep 2002
Distribution: WinLinux 2001 (for now)
Posts: 8

Rep: Reputation: 0
#@!?$# stdout problem!!


I'm very new to shell scripting, and I need to append stdout to a file. I do this using

command >> file

this works fine, except that I want the data to be appended on the same line, with no space in between the existing data and the new data, for example, if stdout contains "", and tempfile contains "31", i get:

13
37

when i want 1337



any ideas on how to do this (or maybe format a file so that everything is on 1 line??)

please help!!!! thankyou.

 
Old 01-21-2003, 07:52 PM   #2
beedyrazzle
LQ Newbie
 
Registered: Sep 2002
Distribution: WinLinux 2001 (for now)
Posts: 8

Original Poster
Rep: Reputation: 0
sorry, im my example, stdout should contain "37", tempfile should contain "13"

see im such a newbie i dont even know hwo to pyte propre;y yet
 
Old 01-21-2003, 08:42 PM   #3
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (Chicago area)
Distribution: Red Hat (8.0, RHEL5,6), CentOS, SuSE (10.x, 11.x, 12.2, 13.2), Solaris (8-10), Tru64, MacOS, Raspian
Posts: 1,106

Rep: Reputation: 64
Re: #@!?$# stdout problem!!

Quote:
Originally posted by beedyrazzle
I'm very new to shell scripting, and I need to append stdout to a file. I do this using

command >> file

this works fine, except that I want the data to be appended on the same line, with no space in between the existing data and the new data, for example, if stdout contains "", and tempfile contains "31", i get:

13
37

when i want 1337

The problem isn't in how your are appending the `37'. The problem is that the `13' already has a newline appended to it by what ever placed it in the file. Try looking at the file at various points in the process using a command like `od -c /tmp/temp.file' (or whatever you called it).

If you were using `echo' to do this, you could do the following:

$ echo -e "13\c" > /tmp/temp.file
$ echo "37" >> /tmp/temp.file
$ cat /tmp/temp.file
1337
$

You can also use `echo -n' in linux but the `\c' special character is recognized by other UNIX shells without needing a special switch. Six of one...

Hope this helps...

Have fun.
 
Old 01-21-2003, 09:03 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
echo -n "31" > /tmp/temp.file
echo "337" >> /tmp/temp.file
 
  


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
/dev/stdout nbframer Linux - Newbie 6 09-10-2005 05:48 PM
what is stdout stefaandk Linux - Newbie 1 09-06-2005 08:20 PM
stdout to file Machiaveli Programming 8 09-04-2005 09:53 AM
problem in restoring stdout to default user_linux Linux - Newbie 2 08-22-2005 03:21 PM
stdout with tk? sk8guitar Programming 1 07-30-2003 03:48 PM


All times are GMT -5. The time now is 08:47 PM.

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