LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 07-29-2009, 04:24 AM   #1
tatoosh
LQ Newbie
 
Registered: Jul 2009
Posts: 13

Rep: Reputation: 1
windows: executeable > filename.txt


How to do so in linux (centos):

In dos-console i can write output to a file with this example:

dir > filename.txt

when i do this in linux:

postmap filename > filename.txt


the filename.txt will be created but with 0 bytes (=empty)
 
Old 07-29-2009, 04:35 AM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

Rep: Reputation: Disabled
No problem for me.
Code:
@Attila:~/Catfon$ ls
catfon35  estel04.gif  src  TIRP.TTF
jdkaye@Attila:~/Catfon$ ls > dir.txt
jdkaye@Attila:~/Catfon$ cat dir.txt
catfon35
dir.txt
estel04.gif
src
TIRP.TTF
I assume you meant something like this.
Did you really mean to type postmap? I have portmap (must be run as root) but not postmap.
cheers,
jdk

Last edited by jdkaye; 07-29-2009 at 04:38 AM.
 
Old 07-29-2009, 04:39 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by tatoosh View Post
How to do so in linux (centos):

In dos-console i can write output to a file with this example:

dir > filename.txt
Works in Linux to, Linux is just way more powerful and
versatile, but that comes at a price/cost: learning.

Quote:
Originally Posted by tatoosh View Post
when i do this in linux:

postmap filename > filename.txt


the filename.txt will be created but with 0 bytes (=empty)
Depends on what postmap does. Do you see anything when
you run it w/o redirection? If you run it with the re-direct,
do you still see something?

In that case it's probably debug/error output, and that's
not on STDOUT but on STDERR. Try postmap filename 2> filename.txt



Cheers,
Tink
 
Old 07-29-2009, 04:44 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Some programs write output to "stderr" instead of regular "stdout". These are different, since there then is a way to display error messages even if the output is redirected.

So for example:

java -version >javaversion.txt

This does not work, at least with Sun Java, since it's outputting to stderr.

java -version &>javaversion.txt

This means send both regular output and error output to the file. This works as expected.
 
Old 07-29-2009, 04:48 AM   #5
tatoosh
LQ Newbie
 
Registered: Jul 2009
Posts: 13

Original Poster
Rep: Reputation: 1
yes i meant postmap

ok that works with "2>".

thanks alot.

now my output file looks like:
postmap: warning: mymails_allowed.db: duplicate entry: "mymail@test.com"

how can i remove all content execpt the mail address, so my output file will be:

mymail@test.com
othermail@here.com
...
 
Old 07-29-2009, 04:59 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Untested (no postfix here):
Code:
postmap filename 2>| sed -r 's/^.*"(.*@.*)"$/\1/' > filename.txt
 
Old 07-29-2009, 05:10 AM   #7
tatoosh
LQ Newbie
 
Registered: Jul 2009
Posts: 13

Original Poster
Rep: Reputation: 1
got it with:
| awk '{print $6}' | tr -d "\""

thx for helping !!
 
Old 07-29-2009, 05:17 AM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by tatoosh View Post
got it with:
| awk '{print $6}' | tr -d "\""

thx for helping !!
Welcome :}

With awk you could save yourself the extra tr ...
Code:
awk -F"[ \"]" '{print $7}'
Admittedly hardly shorter, but it saves you one
extra process ...
 
Old 07-29-2009, 05:45 AM   #9
tatoosh
LQ Newbie
 
Registered: Jul 2009
Posts: 13

Original Poster
Rep: Reputation: 1
ok thanks!
now i need only the first line and did it with 'head'

how to write the head output in a variable?
example:
$myvar=head -1 1.txt

doesnt work
 
Old 07-29-2009, 06:31 AM   #10
vonbiber
Member
 
Registered: Apr 2009
Distribution: slackware 14.1 64-bit, slackware 14.2 64-bit, SystemRescueCD
Posts: 533

Rep: Reputation: 129Reputation: 129
Quote:
Originally Posted by tatoosh View Post
ok thanks!
now i need only the first line and did it with 'head'

how to write the head output in a variable?
example:
$myvar=head -1 1.txt

doesnt work
1. to assign a value to a variable:
myvar=...
(and not $myvar=...)

2. to store the contents of 1st line into the 'myvar' variable:
myvar="$(head -n1 1.txt)"

then to display the value of myvar variable:

echo "$myvar"
 
Old 07-29-2009, 06:51 AM   #11
tatoosh
LQ Newbie
 
Registered: Jul 2009
Posts: 13

Original Poster
Rep: Reputation: 1
ok thx again
 
  


Reply



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
Standalone executeable file m_anzaralam Linux - Newbie 2 03-05-2009 01:10 AM
cat onelinefile.txt >> newfile.txt; cat twofile.txt >> newfile.txt keep newline? tmcguinness Programming 4 02-12-2009 06:38 AM
Can Perl do this? "sed -ie '3d' filename.txt" gctaylor1 Programming 2 08-29-2008 06:42 PM
grep from filename.txt can't get the whole line papasj Programming 3 02-25-2008 12:38 PM
using commands to output path, filename and info to a txt file bob_man_uk Linux - General 3 05-11-2006 02:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:46 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
Open Source Consulting | Domain Registration