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 10-13-2012, 09:42 AM   #1
rich123
LQ Newbie
 
Registered: Oct 2012
Posts: 3

Rep: Reputation: Disabled
trouble using stdin/pipelines/python


i have been given a file that includes 4 columns. i need to extract the 4th columns data and then output it into a file. the file i will output it to is a python file and that contains a formula. The formula will take the numbers and then find the average. i need to do all this using a pipeline. any help?

thanks
 
Old 10-13-2012, 11:35 AM   #2
foodown
Member
 
Registered: Jun 2009
Location: Texas
Distribution: Slackware
Posts: 611

Rep: Reputation: 219Reputation: 219Reputation: 219
Quote:
Originally Posted by rich123 View Post
i have been given a file that includes 4 columns. i need to extract the 4th columns data and then output it into a file. the file i will output it to is a python file and that contains a formula. The formula will take the numbers and then find the average. i need to do all this using a pipeline. any help?

thanks
Hmmm ... this wouldn't be homework, would it?

Even if so, getting the fourth column could be achieved with awk, or with egrep, or probably many other ways.

It seems mostly like this is all about the I/O redirection.

Is this homework?
We have rules against giving people answers to homework.

Last edited by foodown; 10-13-2012 at 11:38 AM.
 
Old 10-13-2012, 03:46 PM   #3
rich123
LQ Newbie
 
Registered: Oct 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
So yee it's uni coursework but it doesnt count towards my grade and coursework is only set so we can learn. ive managed to work out the awk command to extraxt the data but dont know the command to input it into the python file? Help would be appreciated
 
Old 10-13-2012, 04:25 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,134
Blog Entries: 2

Rep: Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839
To connect programs using stdin and stdout you usually use pipes.
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html
 
Old 10-14-2012, 03:13 PM   #5
rich123
LQ Newbie
 
Registered: Oct 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
i know it's using pipes but i cant find the right command.

basically i have a file called 'mean' which is written in gedit and is a python file. another file called walk.csv. I need to extract the data from walk.csv (which i can do) and then pipeline it in to the 'mean' file (which i cant do)

so far i am using this awk -F"," '{print $4}' walk.csv | mean

the terminal says it doesnt understand the mean command (because it isnt a command, it is the file name). if i put '>' in front of 'mean' , it just overwrites the file. any ideas?
thanks
 
Old 10-14-2012, 07:51 PM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,134
Blog Entries: 2

Rep: Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839Reputation: 4839
If you want a Python program to be executed and to read the content from a pipe in that Python program you have to:
a) make the Python program executable (and use a proper shebang or start it with the Python interpreter)
b) handle the pipe in the Python program: http://docs.python.org/library/sys.html#sys.stdin
 
  


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
python: reading from stdin with a timeout eantoranz Programming 6 07-09-2009 04:00 PM
Python: Stdin and python apps fighting? enigma_0Z Programming 2 07-15-2008 08:45 AM
Bi-directional pipelines ggeeoo Linux - Newbie 2 09-03-2006 03:02 PM
pixel pipelines? tnelson42345 Linux - Hardware 1 11-12-2005 12:25 PM
6800LE unlocking pipelines and shaders Sapphire Linux - Software 1 12-29-2004 02:16 AM

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

All times are GMT -5. The time now is 10:14 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