I'm working on a perl-awk loop combination and what I want to do is read in the first line of values.exp and pass that value to test1.exp; next, read in the second line of that file and pass that value to test2.exp.
Which would mean:
values.exp:
test1.exp
test2.exp
output:
and i would like to do that x times
here is my script so far:
With this script i have to change $3 manually, but values are written in values.exp --> so awk should read in this lines for every file.
Could you please help me get this thing done automatically?
Thank you in advance,
Tobi
Last edited by Franklin52; 04-12-2012 at 08:29 AM..
Reason: Please use code tags for code and data samples, thank you
There is nothing in this code perl couldn't do alone nor awk.
Does x-times mean you give a value and it reads the values from values.exp that number of times, ie. always those 2 over and over and add these to those 2 output files?
If yes and I understood it correct, then here some awk code (5 times):
In your code you check for some special NR and have some other values as described in the output example, but maybe you can alter/implement it.
Last edited by zaxxon; 04-12-2012 at 09:17 AM..
Reason: altered code so cycle number is in filenames and added header
I have 136 file (test1.exp, test2.exp, ....) and the values.exp file with 136 lines.
Now i want to use the first line of values.exp and write that to $3 of test1.exp. Then the second line of values.exp and write the value to $3 of test2.exp and so on...
My Perl script is working, but i don't want to change the $3 value in my script for all 136 files manually. So i created values.exp which have all 136 values in 136 lines.
Ok, I think I got it.
I created 1 file with 4 values to be distributed:
I then created 4 target files with this content, 5 lines where line 3 is the line to be replaced:
Then the line to read the value file and replace with GNU sed's -i option, which alters files in place so you don't have to create a temporary file, inside a while loop:
Note the red 3 which is the line number. In your case it would be 2498 I guess.
Here the result:
Hopefully this is what you are looking for and hopefully you have GNU sed or a similar implementation with -i. Else perl alone can be used with -i or some commands being piped into ex etc.
thanks again for your help.
Meanwhile I changed some things again and now I would need help again:
I still have a value file, but know my values are in column 2; in column 1 is a corresponding value:
And I still have got my test-files, but the name of the testfiles are not numbered in a row, so i cannot use the $COUNT settings. But the number corresponds to the column 1 in the value file.
test114 file:
test655 file:
So what I want to do is to read the number XXX (i.e. 144, 655,...) in my test file name, find the corresponding value (in column 2) in the value file and replace the "replace"-line in file number655 with the value. I would like to do this for all my files.
So I should and up with:
test114 file:
test655 file:
Thanks in advance,
Tobias
If you don't mind temporary files being made:
actually this would be more robust in that it won't kill line 3 if the value wasn't read in the input file (i.e. give it a test999 but had no 999 key)
Last edited by neutronscott; 04-17-2012 at 11:30 AM..
Reason: more robust
I have files named with different prefixes. From each I want to extract the first line containing a specific string, and then print that line along with the prefix.
I've tried to do this with a while loop, but instead of printing the prefix I print the first line of the file twice.
Files:... (3 Replies)
Hello ppl
I have a requirement to split (cut in unix) a file (A.txt) which is a pipe delimited file into A1.txt and A2.txt
Now I have to join (paste in unix) this A2.txt with external file A3.txt to form
output file A4.txt which should be CSV (comma separated file) so that third party can... (25 Replies)
Hi Forum.
I did some google search on what I'm trying to do but I cannot get my code to work correctly. I have 2 files which are very large and I want to read text from file1 and search in file2 - if present, keep the records.
I've tried fgrep -f file1 file2 but it is too slow.
File1:... (10 Replies)
Hi,
First of all sincere apologies if I have posted in a wrong section ! Please correct me if I am wrong !
I am very new to UNIX scripting.
Currently my problem is that I have a code file at the location /home/usr/workarea/GeneratedLogs.log :-
Code :-
(Feb 7, 571 7:07:29 AM),... (4 Replies)
Pls help me on this. I have to 2 files like shown below:
File 1
TAIJM
AXPKIM
BEMGW
File 2
PXMPA
JYGE
IMJP
What i want to do is to paste both file to a new file on thir format:
File 3
TAIJM PXMPA
AXPKIM JYGE
BEMGW IMJP
I tried cat and print, but it doesn't work. Cn... (6 Replies)
Hi,
I have two files with the format shown below. I need to read first field(value before comma) from file 1 and search for a record in file 2 that has the same value in the field "KEY=" and write the complete record of file 2 with corresponding field 2 of the first file in to result file.
... (11 Replies)
Hi Unix gurus
I have a file containing 2 coloumns. I would like to do a script which reads the lines and executes a command like this:
command <field1> parameters <field2> some more parameters
Please let me know how you would do this without AWK, SED or any other mini language (for special... (5 Replies)
Hi Experts.
I need to list the file and the filename comes from the file ListOfFile.txt.
Basicly I have a filename "ListOfFile.txt" and it contain
Example of ListOfFile.txt
/home/Dave/Program/Tran1.P
/home/Dave/Program/Tran2.P
/home/Dave/Program/Tran3.P
/home/Dave/Program/Tran4.P... (7 Replies)
Hi,
I need to read two colums(4th and 5th) from a file and do some manipulation
Input file is
401500 IOC Q 14 14
406200 LC Q 1 1
410124 IOC Q 5 4
410124 LC Q 11 8
410132 IOC Q 230 229
410148 IOC Q ... (3 Replies)
Hi,
I've got a file like the following:
Starting to process segment 0 (and symmetry related segments)
Number of (cancelled) singularities: 0
Number of (cancelled) negative numerators: 0
Segment 0: 5.49secs
Starting to process segment 1 (and symmetry related segments)
Number of... (7 Replies)