how to use pipes + redirection to create two files?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to use pipes + redirection to create two files?
# 1  
Old 05-03-2006
how to use pipes + redirection to create two files?

# this works
# creates two.txt
(echo one;echo two;echo three;) | (
( grep two > two.txt )
)

# wamt this to create two files:
# two.txt containing "two" and three.txt containing "three"
# Both files get created, but three.txt is empty
# is there a way to do this?
(echo one;echo two;echo three;) | (
( grep two > two.txt )
( grep three > three.txt )
)

Thanks for helping me learn unix scripting!
# 2  
Old 05-03-2006
how about:
Code:
(echo "one"; echo "two"; echo "three") | grep -e "two" -e  "three"

# 3  
Old 05-03-2006
Code:
(echo "one"; echo "two"; echo "three")|xargs -i ksh -c '[[ ! -z $(echo {}|grep two) ]] && echo {}|grep two >2.txt;[[ ! -z $(echo {}|grep three) ]] && echo {}|grep three >3.txt'

# 4  
Old 05-03-2006
Thanks klashxx. I had to replace "ksh" with bash and it worked for me.

It's pretty hard for me to understand, but I will study it and work on my bash fu Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to create or convert to pdf files from csv files using shell script?

Hi, Can anyone help me how to convert a .csv file to a .pdf file using shell script Thanks (2 Replies)
Discussion started by: ssk250
2 Replies

2. Shell Programming and Scripting

Create multiple zip files each containing 50 xml files.

Hi, Is there a direct command or need to write a shell script for following requirement? Everyday a folder is populated with approx 25k to 30k xml files. I need to create multiple zip files in the same folder each containing 50 xml files. The last zip file may or may not contain 50 xml files.... (6 Replies)
Discussion started by: Rakesh Thobula
6 Replies

3. Shell Programming and Scripting

How to create zip/gz/tar files for if the files are older than particular days in UNIX or Linux?

I need a script file for backup (zip or tar or gz) of old log files in our unix server (causing the space problem). Could you please help me to create the zip or gz files for each log files in current directory and sub-directories also? I found one command which is to create gz file for the... (4 Replies)
Discussion started by: Mallikgm
4 Replies

4. Homework & Coursework Questions

Using Pipes and Redirection

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Create a pipe to show the number of people who are logged into the system right now. Create a pipe to show... (2 Replies)
Discussion started by: lakers34kb
2 Replies

5. Shell Programming and Scripting

create pipes based on the column

i get text files with Action & Adventure|2012: Supernova NR|2009-11-01 00:01:00|2010-05-01 23:59:00|Active|3 Action & Adventure|50 Dead Men Walking|2010-01-05 00:01:00|2010-06-30 23:59:00|Active|4 Action & Adventure|Afterwards|2009-11-26 00:01:00|2010-03-26 23:59:00|Deactivated|6 Based... (3 Replies)
Discussion started by: ramse8pc
3 Replies

6. Shell Programming and Scripting

Possible to combine inline redirection with pipes?

Would like to use a here document in a shell script with sqlplus and pipe the output to sed (etc.) before ultimately redirecting the lot to a file, e.g: # sqlplus -S user/pass <<EOF SELECT * FROM table quit EOF | sed 's///g' > outputfile Have tried various permutations to no avail. Any... (2 Replies)
Discussion started by: cs03dmj
2 Replies

7. Shell Programming and Scripting

redirection output in two files

I want to redirect output of my script to two logfiles. I tried this : ./run.sh -c APP | tee >(grep " " > AppLogs.log) >(grep "XYZ" > xyz.log) >dev/null but this does not solve my purpose because logfile xyz.log remains empty untill i stop my script, i want both files, AppLogs.log and... (4 Replies)
Discussion started by: cmdup
4 Replies

8. UNIX for Dummies Questions & Answers

Create individual tgz files from a set of files

Hello I have a ton of files in a directory of the format app.log.2008-04-04 I'd like to run a command that would archive each of these files as app.log.2008-04-04.tgz I tried a few combinations of find with xargs etc but no luck. Thanks Amit (4 Replies)
Discussion started by: amitg
4 Replies

9. Filesystems, Disks and Memory

PIPEs and Named PIPEs (FIFO) Buffer size

Hello! How I can increase or decrease predefined pipe buffer size? System FreeBSD 4.9 and RedHat Linux 9.0 Thanks! (1 Reply)
Discussion started by: Jus
1 Replies
Login or Register to Ask a Question