cat-ing a group of files into two outputs


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cat-ing a group of files into two outputs
# 1  
Old 11-05-2009
cat-ing a group of files into two outputs

I have some logic which uses CAT to concatenate group of files, 'SED'-ing some field values and piping the output to one file :-

cat `echo $infilename|sed '{
s/.filestream./'${file_stream}'/g
s/.field2./'${jobopt2}'/g
s/.sb_odate./'${SB_ODATE}'/g
}'` >$outfilename

Now I need to stream the output of that operation to two output files, conditional on the value of the first character of each line of the input files......if the first character is 7 or 8 write the record to one output and if not write it to the alternative output file

I know I could read through the group of input files and add a grep........but can anyone suggest a way of doing it with just one read through the input ?
# 2  
Old 11-05-2009
If you switched to something like GNU awk, you certainly could do what you wanted to do in one pass using redirection from the print statement.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Loop grep, outputs in files

Hi, I try to create a simply code but I have problems... Ubuntum, Bash version: 4.3.46 Bash INPUT file (csv): TS133_29BC,xx2274305 TS133_29BC,rps4576240 av137_37BC,wfs2274305 av137_37BC,ftrs4576240 T1S138_30BC,rfss2255526 T1S138_30BC,rgas2274305 OUTPUT files (csv): File TS133_29BC... (6 Replies)
Discussion started by: echo manolis
6 Replies

2. Shell Programming and Scripting

ftp'ing multiple files to the remote server

unix shell script (2 Replies)
Discussion started by: giridhar276
2 Replies

3. Shell Programming and Scripting

create outputs from other command outputs

hi friends, The code: i=1 while do filename=`/usr/bin/ls -l| awk '{ print $9}'` echo $filename>>summary.csv #Gives the name of the file stored at column 9 count=`wc -l $filename | awk '{print $1}'` echo $count>>summary.csv #Gives just the count of lines of file "filename" i=`expr... (1 Reply)
Discussion started by: rajsharma
1 Replies

4. Shell Programming and Scripting

grep'ing and sed'ing chunks in bash... need help on speeding up a log parser.

I have a file that is 20 - 80+ MB in size that is a certain type of log file. It logs one of our processes and this process is multi-threaded. Therefore the log file is kind of a mess. Here's an example: The logfile looks like: "DATE TIME - THREAD ID - Details", and a new file is created... (4 Replies)
Discussion started by: elinenbe
4 Replies

5. Shell Programming and Scripting

Cat'ing a multiple line file to one line

I am writing a script that is running a loop on one file to obtain records from another file. Using egrep, I am finding matching records in file b, then outputing feilds of both into another file. **************************** filea=this.txt fileb=that.txt cat $filea | while read line do... (1 Reply)
Discussion started by: djsal
1 Replies

6. Shell Programming and Scripting

Help in FTP'ing multiple files

Hi, I have written the following FTP script to get the multiple files from remote server to local server. My problem is that 'mget *' is not working in the script. I also tried with 'mget *.txt', 'mget *.*' etc. without any success. It do not copy any file to local server. In the script, Prompt... (10 Replies)
Discussion started by: berlin_germany
10 Replies

7. Shell Programming and Scripting

FTP'ing files with filenames in mail messege

Hi, I have created the following FTP script, which transfers daily “.txt” files from remote server in to a timestamped folder on local server. Once all files are FTP'ed, it then deletes files from remote server. When files are FTP'ed, I get a mail messege like, “Files are successfully transfered”,... (1 Reply)
Discussion started by: berlin_germany
1 Replies

8. UNIX for Dummies Questions & Answers

tar'ing and zipping files

If I have a directory /directory1 and want to tar and zip everything in it into a file new_tar.tar.gz on disk (not tape) How can I do it? I tried tar -cv /new_tar.tar /directory1/* But I got an error: tar: /dev/rmt/0: No such device or address (4 Replies)
Discussion started by: FredSmith
4 Replies

9. Solaris

Error tar'ing files to tape

I'm trying to tar a bunch of files off to a tape, but for one specific file (it is fairly large, roughly 10Gb) I get the error: too large to archive Does tar have a limit of the size of file it can write off to tape? I'm using SunOS 5.8. Thanks! -Fred (6 Replies)
Discussion started by: FredSmith
6 Replies

10. UNIX for Dummies Questions & Answers

grep'ing for text within a bunch of files...?

I have, say, a dozen files, and I want to grep for a string of text within them. I don't remember the exact syntax, but let me give it a shot and show you an idea here... find . -type f -exec grep thisword {} \; ...and there's a way to put more than one grep into the statement, so it will tell... (1 Reply)
Discussion started by: kitykity
1 Replies
Login or Register to Ask a Question