Sponsored Content
Top Forums Shell Programming and Scripting Redirecting the results to different output files Post 302973368 by am24 on Tuesday 17th of May 2016 08:47:01 AM
Old 05-17-2016
Redirecting the results to different output files

Hi All,

I am trying a shell script and need your help on taking the results to different output files.
I have tried the below code:

Code:
nawk '
{CNF = (length()-10)/7
 printf "%9s", substr ($0, 1, 9)
for (i=0; i<=CNF; i++) T[i+2] = substr ($0, 10+i*7, 7)
TMP = 100 - (T[8] + T[9] + T[10] + T[11] + T[12] + T[13] + T[14] + T[15] + T[16] + T[17] + T[18])
for (i=2; i<=CNF+2; i++){printf "%7s", T[i]; if(i==18) {printf "%7.3f",T[i]=TMP}}
printf RS
}' input > output


My Input:

Code:
032016501  3.974 96.026 20.605 28.838 21.722 28.835  0.306  0.000 66.204  0.229  0.000 16.707  5.348  0.000  3.142  0.000  5.929 71.299 28.701  6.662 93.338  2.360 97.640  0.000100.000 46.620 53.380 43.192 56.808 66.447 16.775  0.063  0.160 16.554 92.911  1.882  0.159  5.048
032016504  3.262 96.738 13.788 26.191 24.911 35.109  0.613  0.000 57.812  0.068  0.000 21.573  6.325  0.000  5.475  0.089  6.624 77.755 22.245  7.786 92.214  4.759 95.241  0.000100.000 47.223 52.777 43.055 56.945 58.410 21.412  0.124  0.225 19.934 92.965  1.397  0.364  5.273
032016505  2.394 97.606 13.972 22.808 25.249 37.971  0.000  0.000 43.433  0.000  0.000 22.217 12.057  0.221  8.796  0.205 12.087 77.008 22.992 13.163 86.837  7.690 92.310  0.000100.000 56.074 43.926 47.104 52.896 43.433 21.925  0.000  0.292 34.351 91.996  0.808  0.000  7.196

My Output:
Code:
032016501  3.974 96.026 20.605 28.838 21.722 28.835  0.306  0.000 66.204  0.229  0.000 16.707  5.348  0.000  3.142  0.000  5.929  2.135 71.299 28.701  6.662 93.338  2.360 97.640  0.000100.000 46.620 53.380 43.192 56.808 66.447 16.775  0.063  0.160 16.554 92.911  1.882  0.159  5.048
032016504  3.262 96.738 13.788 26.191 24.911 35.109  0.613  0.000 57.812  0.068  0.000 21.573  6.325  0.000  5.475  0.089  6.624  1.421 77.755 22.245  7.786 92.214  4.759 95.241  0.000100.000 47.223 52.777 43.055 56.945 58.410 21.412  0.124  0.225 19.934 92.965  1.397  0.364  5.273
032016505  2.394 97.606 13.972 22.808 25.249 37.971  0.000  0.000 43.433  0.000  0.000 22.217 12.057  0.221  8.796  0.205 12.087  0.984 77.008 22.992 13.163 86.837  7.690 92.310  0.000100.000 56.074 43.926 47.104 52.896 43.433 21.925  0.000  0.292 34.351 91.996  0.808  0.000  7.196

With the above code, i am inserting a new field at 19th field in my Input.The new field calculations you can find in the code. I have got my desired results in the output.

Problem is, i want to apply this same code on 7 different files and take output to different files. I have tried but not able to get it done.

Can anyone help me on how to apply the same code on different input files and taking the results to different output files ?

Thanks in advance,
am24
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Redirecting output to multiple log files?

If I wanted to redirect output to multiple log files, what would be the best way to do that? echo "Unix is awesome" >>unixgod.log >>unixgod.log (3 Replies)
Discussion started by: darthur
3 Replies

2. Shell Programming and Scripting

Redirecting OUTPUT

Hi, I want to move the output of a command/script to a file as well as to to be displayed on stdout. Can anybody help me in this. Thanks in advace .. -Chanakya M (1 Reply)
Discussion started by: Chanakya.m
1 Replies

3. Programming

execl() + redirecting output to text files

Im currently using execl() to run the ls command and redirect the output to a text file. Unfortunately, when I check the text file, no information has been written to it. I am calling execl() with the ls command like this execl( "/bin/ls" , "-al" , '>' , "dirlist.txt" ,(char *) 0 ); ... (5 Replies)
Discussion started by: JamesGoh
5 Replies

4. Shell Programming and Scripting

Redirecting echo output to 2 flat files

Hello all, I have the following 2 questions.. 1) I would like to capture the output of an echo command to 2 different files at the same time. This does not seem to work. Any ideas? echo ==== started on `date` ==== >> res1.log res2.log 2) Would it be possible to just get the 5th... (2 Replies)
Discussion started by: luft
2 Replies

5. Shell Programming and Scripting

Redirecting to different output files with awk.

Well, it didn't take me long to get stumped again. I assure you that I'm not mentally deficient, just new to scripting. So, here's the gist. I want to redirect output from awk based off of which branch of an if-else statement under which it falls. #!/bin/bash #some variables... (2 Replies)
Discussion started by: mikesimone
2 Replies

6. Shell Programming and Scripting

Redirecting output to file

Hi, Below is the whole string which is to be redirected to the new file. su - oracle -c "exp $user/$pass file=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.dmp log=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.log tables=table1,table2 statistics=none" ... (3 Replies)
Discussion started by: milink
3 Replies

7. Shell Programming and Scripting

awk help: Match data fields from 2 files & output results from both into 1 file

I need to take 2 input files and create 1 output based on matches from each file. I am looking to match field #1 in both files (Userid) and create an output file that will be a combination of fields from both file1 and file2 if there are any differences in the fields 2,3,4,5,or 6. Below is an... (5 Replies)
Discussion started by: ambroze
5 Replies

8. Shell Programming and Scripting

Redirecting the output

For example, if we run the below command, symcfg list -thin -pool , results in an output most of the times and if the out is generated i'm able to redirect the output to a file. but sometimes it doesnt result any output and even though the output is being redirected, i can see "No Thin Pools "... (2 Replies)
Discussion started by: web2moha
2 Replies

9. Post Here to Contact Site Administrators and Moderators

Redirecting grep output to multiple files

Hi All, I am trying to redirect the grep output to multiple files, can you please help with that. Below is the command im using to match my pattern grep \<proxyType\>$PxyType $DIR/EndureFiles.json > File_Name*.json Note : $DIR and $PxyType is already defined in my script Im able... (0 Replies)
Discussion started by: Deena1984
0 Replies

10. Shell Programming and Scripting

Awk: Print Error While Redirecting output in multiple Files

Hi, I have a following code in which I am unable to redirect to multiple files. Can anybody please help with some corrections awk -F, '{ if ( substr($1,26,2)=="02" && substr($1,184,14)=="MTSCC_VALFIRST") { array1++ array2++ array3++ } else if (substr($1,26,2)=="03" &&... (4 Replies)
Discussion started by: siramitsharma
4 Replies
CG(1)																	     CG(1)

NAME
cg - Recursively grep for a pattern and store it. SYNOPSIS
cg [ -l ] | [ [ -i ] pattern [ files ] ] DESCRIPTION
cg does a search though text files (usually source code) recursively for a pattern, storing matches and displaying the output in a human- readable fashion. It is intended to give some of the functionaly of AT&T's cscope(1) tool, with the advantages of simplicity and not being language-specific. The script will colorize output if configured as such. It is typically run with a Perl regular expression to search for. The search can be made case insensitive by using the -i option. A list of files may also be specified with an additional argument after the pattern. Put the files pattern in quotes to make it be matched by Perl rather than by the shell. Running the script with no arguments will recall the results of the previous search. After the search, entries found can be edited using the vg(1) script. The -l option shows the last log made. SOME EXAMPLES
cg - alone recalls the previous search results. cg -i pattern - search the default list of files for all files matching the pattern (and case-insensitively). cg pattern '*.c' - search recursively for pattern in all *.c files. This automatically converts '*' to '.*' and '.' to '.' for you and does a Perl pattern match on all files in the tree. cg pattern *.c - search through the shell-expanded list of *.c files, so not done recursively (in other words, only the files your shell pass to the script as arguments). cg -l - show the last log made. COMMAND-LINE OPTIONS -i Do a case-insensitive search. -l Show the last log made. -p Toggle the default pager option. cg has a bulit-in pager function, which can be enabled or disabled by default (in .cgvgrc). If the default is enabled, this option disables the pager; if the default is disabled, this option enables it. -P Force the built-in pager to be disabled. FILES
${HOME}/.cglast Log file of the last search. ${HOME}/.cgvgrc Per-user configuration file (if the defaults are not desireable). ${HOME}/.cgvg/* Log files in $HOSTNAME.shell_pid form with the log of the last search. SEE ALSO
vg(1), perl(1), find(1), grep(1), cscope(1) AUTHOR
cg was written by Joshua Uziel <uzi@uzix.org>. 13 Mar 2002 CG(1)
All times are GMT -4. The time now is 08:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy