Hello,
first, I apologize if this is trivial or in the wrong place. I'm new to all of this and I don't know how everything works.
I was wondering if I could get some tips on text redirection. What I want to do is to take some characters from a file and input them in another one. More specifically, I have a large "table" file which includes all the numbers I have. These numbers need to be written at specific lines and places in other files. Each of these output files needs data from the "table", but each from a different column; I wanted to automate the process to generate these output files without having to look at the "table" and manually transcribe the numbers every time.
So far what I've come up with is a simple line of code in awk to extract the desired column. The intention is to then copy each value of the column in the appropriate place in a blank output file. The blank file is like a normal one except all the values are XXXXX (or similar string). The idea was to use sed or awk to substitute XXXXX with the appropriate value. To do this, I need to be able to direct data from one file to another, and I'm not sure how to do that.
I probably made this sound a lot more complicated than it is. I welcome all suggestions, even if it's just to say that my method is stupid and there's a better way to do it. I'm quite new to Linux, so please be patient. I know a little (VERY little) about awk and sed, but don't hesitate to point me to better functionalities if you think that they can be more useful.
Thank you for your attention.
This is probably doable with awk, which is particularly good at dealing with tabular data.
Even with a good description there's still a lot of ambiguity left -- what column separators you use if any, etc, etc. If you could post a sample of your input data, the output data you'd want from it, and explain the relation between the two, most of the ambiguity would be gone.
Ok, so here's a sample of what I have:
This is the first 5 lines of the master table, as a simple text file edited with vim. Each column has values for that particular percentage combination: the first one for 100-0, the second for 90-10 and so on. There are another 50 or so lines after that with more values of different features at that percentage combination.
My output looks like this:
In particular, this is the 100-0 combination. The format of the output is fixed: this is the way it has to be in order to be read by the program I'm using. There are another 40 or so lines after that for the remaining features and parameters.
In the third line, starting with cd, there are two values which vary in each percentage combination. The script needs to read the value from the table and write it in the correct column. For example, to prepare the 90-10 output file, I want it to read the third column on the third line (10.809) and write that down in the second column of the third line of the output file, then take the third column on the fifth line (0.7902) and write it on the third column of the third line of the output file. I want this to be repeated for every other parameter. I don't care if I need many lines to specify where everything goes, as long as it's automated. Is there a way to do this?
My first idea was to extract each column of the table in a temporary, intermediate file, then copy across from this to a blank output file, which has XXXXX instead of numbers, by giving a command to substitute the first XXXXX it finds with the first value of the column, then the second with the second and so on. What I don't know what to do is how to redirect the substitution from a file to another file.
I would've been tempted to generate all-new files rather than modify existing ones. It'd be much easier to make sure the formatting is right that way. Fixed-width columns instead of sanely tabbed data in particularly are a bear to edit with anything. Still, though, I think you can do this with awk. 50 lines isn't a lot of data to hold in memory.
Also: as a precaution, I still suggest creating new files instead of editing the old ones, since any mistake in editing the originals could potentially ruin them.
That specific line is not supposed to be edited: the values of hm are the same across all output files. In the output file, the first column is the "mass" data, while the second is the "radius" data. So the value labeled as cdmass goes in line 3 column 2, the value labeled as cdradius in line 3 column 3, hdmass in line 4 column 2, hdradius in line 4 column 3, to use the examples shown.
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)
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)
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)
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)
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)
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)
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)
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)