ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a bash program that gives output in the commad prompt eg.
Code:
00 12 03 C2 EE ...
I want to grep a line containing value 'C2' and put the line into a file.
I tried:
Code:
$./serial 1 | grep C2 > data
but it doesn't work. I don't get any errors but there is no data in the file. BTW, serial is the program that monitors serial port 1 and spits it out on the command.
Maybe this serial program is not printing to stdout, but instead stderr. When you do your command with grep, do you see the output of serial printed to the terminal in the same way that you would when you run without the grep?
If so, you should specify that the stderr should be sent to the stdout file handle:
Billymayday:
I get exactly what I want. Everything is ignored except the line containing 'C2'. But when added the last part "> data", nothing is written to it.
>> appends to an existing file.
> truncates existing files.
Please can you enter these commands, and paste the results (with the commands too). pease everything.
Code:
echo $SHELL
id
ls -ld .
lsattr -d .
touch mytestfile
ls -l mytestfile
./serial 1 > mytestfile
cat mytestfile
./serial 1 |grep -i C2 > mytestfile
cat mytestfile
Please enclose your pasted results in [code] tags to aid readability. Don't omit anything. I'd like to see all output, and the commands as you typed them. If the un-filtered output of serial 1 is very long, please link to a nopaste posting for that output.
Last edited by matthewg42; 12-15-2007 at 06:18 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.