Command that creates file and also greps that file?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Command that creates file and also greps that file?
# 1  
Old 06-18-2009
Command that creates file and also greps that file?

I have a command that does something and then creates a log file (importlog.xml).

I then want to grep that newly created log (importlog.xml) file for a certain word (success).

I then want to write that grep result to a new file (success.log).

So far I can run the command which creates the file. I can also do the grep.

However I cannot do them together in one command. Is it possible to create a file and then grep that file in the same command?

This is my grep command which I have just put on the end of my other command which first created the file importlog.xml:

| grep SUCCESS importlog.xml > SUCCESS.log

The two commands are seperated using | pipe.

Is this possible or does the grep have to be run seperately after the first command which creates the importlog.xml file?

I am using Solaris.

Thank you.
# 2  
Old 06-18-2009
Hammer & Screwdriver Maybe a ; instead of a | between commands

Since I do not have your first command, I tried to recreate what could be happening. I delete existing op_it.lst file (to make sure I will only run with NEW output). I then run a command directing output to that file. Next I use the ; to run next command. I am getting my expected result.
The | takes output 'to that point' and uses as input to next command; thus your issue of first command creating text file output and not getting anything with second command. Solved when I used ; instead.

Code:
> rm op_it.lst
> ls op_it* > op_it.lst ; grep csv <op_it.lst
op_it_2.csv
op_it_3.csv
op_it_4.csv
op_it_recpt.csv
op_it_ua1.csv
op_it_yr.csv

# 3  
Old 06-18-2009
Thanks. That did the trick.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Writing a script that creates a 1GB file with zeros using dd

I am new to Linux. Using latest version of Ubuntu. I want to make a script that creates a 1GB file filled with zeros using dd and then formats the file as vfat with a label of "MYFILE". If anyone can help me it would be appreciated. (1 Reply)
Discussion started by: amandasaza08
1 Replies

2. Red Hat

Script creates additional file

Hi, I have created a test script like this : # cat script1.sh DAY=$(date +%d) MONTH=$(date +%b) YEAR=$(date +%Y) BC01="Blast_BC01" BC15="Blast_BC15" DIR1="$MONTH$YEAR_$BC01" DIR2="$MONTH$YEAR_$BC07" DIR3="$MONTH$YEAR_$BC15" if ;then mkdir -p "$YEAR/$DIR3" fi # When I... (5 Replies)
Discussion started by: anaigini45
5 Replies

3. Shell Programming and Scripting

Writing a script that creates a 1GB file with zeros using dd

I am new to Linux. Using latest version of Ubuntu. I want to make a script that creates a 1GB file filled with zeros using dd and then formats the file as vfat with a label of "MYFILE". If anyone can help me it would be appreciated. (9 Replies)
Discussion started by: paviter619
9 Replies

4. Shell Programming and Scripting

Lock file creates with '?'

Hi, I am trying to create a lock file with the following code but for some reason after file is created it has wrong name "PASP?.lock??" Please let us know how to get rid of these '??' from file name and from where they are coming? #!/bin/ksh... (6 Replies)
Discussion started by: sandy162
6 Replies

5. UNIX for Dummies Questions & Answers

Redirection creates empty file

I'm using a script that does some modifications to data on disc and updates the database. The script (perl) uses STDOUT so the results are printed to the screen. I don't have permissions to modify the script. I want to capture the results in a file so I can see if errors occurred and also keep... (3 Replies)
Discussion started by: surib
3 Replies

6. Shell Programming and Scripting

Script sometimes creates an empty file

I have a script that runs ditto for me, and occasionally (if I exit the script while ditto is running in the background) it will leave an empty file named 0 in the script's directory. The next time I run the script, it generates incorrect data because of this file. I know I can easily insert a... (1 Reply)
Discussion started by: reid
1 Replies

7. Shell Programming and Scripting

Script sometimes creates an empty file

I have a script that runs ditto for me, and occasionally (if I exit the script while ditto is running in the background) it will leave an empty file named 0 in the script's directory. The next time I run the script, it generates incorrect data because of this file. I know I can easily insert a... (1 Reply)
Discussion started by: reid
1 Replies

8. Shell Programming and Scripting

Script Optimization - large delimited file, for loop with many greps

Since there are approximately 75K gsfiles and hundreds of stfiles per gsfile, this script can take hours. How can I rewrite this script, so that it's much faster? I'm not as familiar with perl but I'm open to all suggestions. ls file.list>$split for gsfile in `cat $split`; do csplit... (17 Replies)
Discussion started by: verge
17 Replies

9. Shell Programming and Scripting

sed in script creates output file ending with '?' (^M)

Hi, I'm trying to use sed within a shell script (bash, running ubuntu). The command works fine from the command line, but when I use it within the script, rather than creating a file with the name I've specified, it creates one that ends with a question mark '?' when you use ls, e.g.... (3 Replies)
Discussion started by: jennykay
3 Replies
Login or Register to Ask a Question