Text redirection


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Text redirection
# 8  
Old 03-16-2012
I need to make eleven output files, each corresponding to a different percentage combination. The format of these files has to be as in the post above.
Suppose we start with the 100-0%. The script needs to take the appropriate parameter and write it in the appropriate place. The first one is cdmass, so it needs to read the value in the table on column 2 (100-0), line 3 (cdradius), and substitute it in the output file at column 2, line 3. The next is cdradius, so it reads the value in the table at column 2 (100-0) line 5 (cdradius) and substitute it in the output file at column 3, line 3.
The same applies to all other parameters: so when making the 90-10 output file, it reads cdmass at column 3, line 3, and substitutes at column 2, line 3 of a new output file.
Essentially, I need a way to point at a specific value from a file identifying by column/line coordinates and to tell the program to substitute it at a specific column/line coordinate of another file.
I hope I've explained what I want to do: I understand that it might be a bit complicated to grasp. If there is a better way of doing it, which there almost certainly is, don't hesitate to tell me rather than chasing my probably needlessly complicated route.
# 9  
Old 03-19-2012
I think this may do close to what you want:

Code:
# hydrogen.awk

FNR == 1 { FILECOUNT++ }

# Load master data table into memory
NR == FNR {     for(N=1; N<=NF; N++)
                {
                        DATA[NR, N]=$N;
#                       printf("DATA[%d,%d]=%s\n", NR, N, $N)>"/dev/stderr";
                }
                next    }

(FNR <= 2) || (FNR > 4) { print > FILENAME ".new"; next }

# All other lines
{
        print $1 " " substr(DATA[FNR,FILECOUNT],1,5) "        " substr(DATA[FNR+2, FILECOUNT], 1, 5) "                                       " $4>FILENAME ".new"
}

Use it like
Code:
awk -f hydrogen.awk mastertable.dat column1file column2file ...

It will produce output files like column1file.new and column2file.new

You must be sure to give it the files in order, as that's how it knows which one is which column.
This User Gave Thanks to Corona688 For This Post:
# 10  
Old 03-20-2012
Thanks for this, I managed to solve my problem.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

about different redirection

explain the redirections 1>, 2>, 3>, ..... and 1< ,2<,3<..... where we use these things thanks Thread moved from AIX forum (2 Replies)
Discussion started by: tsurendra
2 Replies

2. Solaris

solaris redirection

Hi I am using solaris 10. When running a grep command with multiple files the output is the same as the order of the input. As soon as I pipe the output to another command then it seems that standard error takes precedence, over standard output and gets sent to the pipe first. ie grep -c... (7 Replies)
Discussion started by: chronics
7 Replies

3. Shell Programming and Scripting

Redirection

Hello All, I am using the below script to gather various tools running by the user, we have more than 100 tools running on the server so my challenge is to redirect memory & cpu load to the file with the name of the tool.so am using the below script i am stucking how to redirect to the file... (2 Replies)
Discussion started by: ajaincv
2 Replies

4. Shell Programming and Scripting

I/O redirection

Hello everyone,I'm reading a book and there's code fragment: exec 3>&1 ls -l 2>&1 >&3 3>&- | grep bad 3>&- exec 3>&- It says that the red part of that code does not close fd 3 but the green does close the fd 3.I can't understand that.....Why?Any predicate will be appreciated.:) (18 Replies)
Discussion started by: homeboy
18 Replies

5. Homework & Coursework Questions

Finding/replacing text and redirection help

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: What command would rename "sequentialInsert", in ~cs252/Assignments/commandsAsst/project/arrayops.h, to... (2 Replies)
Discussion started by: lothwen
2 Replies

6. UNIX for Dummies Questions & Answers

Help with Redirection

Hi Guys, I m new to UNIX and new to this forum. Was wondering if someone can help me understand redirection (standard input output pipeline etc) for starters, not too sure what this would mean who | sort > sortedfile | pr | lp im starting to understand common commands but when throwing... (2 Replies)
Discussion started by: jmack123
2 Replies

7. Shell Programming and Scripting

redirection

Hi, The code below works, it's a part of a bash shell script that serve to search a pattern $pattern_da_cercare in the files contained in a directory $directory_iniziale. Now the proble is: How can I redirect stderr to a file? PS: so I want to redirect ALL the errors to a file. I tryed... (9 Replies)
Discussion started by: DNAx86
9 Replies

8. Shell Programming and Scripting

redirection stdin

hello all, I need to create a password change utility for a database. I need to gather at the command line the username, password and database sid. I have the program currently doing this. What I would like to do is not have the new password appear on the screen when I do my read command.... (2 Replies)
Discussion started by: whited05
2 Replies

9. Programming

Help with redirection

Here is my problem. I don't know make this redirection thing work. The output file (called output.c) looks like this #include<stdio.h> int main() { int k; int m; print f("%d\n", k); printf("%d\n", m); return 0; } the input file(called input.c) is this #include<stdio.h> int... (2 Replies)
Discussion started by: Shallon1
2 Replies
Login or Register to Ask a Question