06-28-2011
The new file basically looks like this:
0.8790063238
0.8474671494
0.7592438321
0.9052356303
0.8498985801
0.940782332
0.7890000695
X
0.8253697252
0.7597086586
0.8380313668
0.8243804613
0.7485355649
It will replace the sixth column of the original file
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Say I had a text file that contained four columns, like the following:
Mack Christopher:237 Avondale Blvd:970-791-6419:S
Ben Macdonor:30 Dragon Rd:647-288-6395:B
I'm making a loop that will replace the fourth column a line in the file with the contents of a variable 'access', but I have no... (6 Replies)
Discussion started by: Sotau
6 Replies
2. Shell Programming and Scripting
Hi,
I have the following text file:
8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm
9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm
10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm
11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies
3. Shell Programming and Scripting
Hi All,
I will really appreciate if you kindly lookinto my requirement below and provide me a solution
First file format test1.txt
qq ww rr tt ee ff
qq ww rr tt ee ff
Second file format text2.txt
aa
aa
Now o/p I want as text1.txt's 4th column replaced... (5 Replies)
Discussion started by: Pratik4891
5 Replies
4. UNIX for Dummies Questions & Answers
Hi,
I have a text file in the following format:
Code:
13412 NA06985 0 0 2 46.6432798439 4 4 4 4
13412 NA06991 NA06993 NA06985 2 48.8478948517 4 4 2 4
13412 NA06993 0 0 1 45.8022601455 4 4 2 4
13401 NA06994 0 0 1 48.780669145 4 4 4 4
13401 NA07000 0 0 2 47.7312017846 2 4 4 4 ... (2 Replies)
Discussion started by: evelibertine
2 Replies
5. UNIX for Dummies Questions & Answers
Hi,
I would like to use sed to replace NA to x ('s/NA/x/g'), but only in the 5th column of the space delimited text file, nowhere else. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies
6. Shell Programming and Scripting
Can anyone please help with this? I have 2 files as given below.
If 2nd column of file1 has pattern foo1@a, find the matching 1st column in file2 & replace 2nd column of file1 with file2's value.
file1
abc_1 foo1@a ....
abc_1 soo2@a ...
def_2 soo2@a ....
def_2 foo1@a ........ (7 Replies)
Discussion started by: prashali
7 Replies
7. Shell Programming and Scripting
Hi,
I have two input files as
File1 :
ABC:client1:project1
XYZ:client2-aa:project2
DEF:client4:proj
File2 :
client1:W-170:xx
client2-aa:WT-04:yy
client4:L-005A:zz
Also, array of valid values can be hardcoded like
Output :
ABC:W:project1
XYZ:WT:project2 (1 Reply)
Discussion started by: aa2601
1 Replies
8. UNIX for Dummies Questions & Answers
Hi,
I have a space de-limited text file. In the fifth column, I would like to switch "1"s with "2"s. How do I go about doing that? Thanks!
Sample input:
0 311000259 0 0 1 1
0 311000397 0 0 1 2
0 311000491 0 0 2 1
0 311000516 0 0 2 1
0 311000541 0 0 1 1
0 311000558 0 0 2 1
0 311000566 0... (1 Reply)
Discussion started by: evelibertine
1 Replies
9. Shell Programming and Scripting
I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file.
Here is the file.
<!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies
10. Shell Programming and Scripting
All,
I have some sample text file(.csv) in the below format. In my actual file there are at least 100K rows.
date 03/25/2016
A,B,C
D,E,F
date 03/26/2016
1,2,3
4,5,6
date 03/27/2016
6,4,3
4,5,6
I require the following output where in the date appeared at different locations need to... (3 Replies)
Discussion started by: ks_reddy
3 Replies
LEARN ABOUT OSX
context::preserve
Context::Preserve(3) User Contributed Perl Documentation Context::Preserve(3)
NAME
Context::Preserve - run code after a subroutine call, preserving the context the subroutine would have seen if it were the last statement
in the caller
SYNOPSIS
Have you ever written this?
my ($result, @result);
# run a sub in the correct context
if(!defined wantarray){
some::code();
}
elsif(wantarray){
@result = some::code();
}
else {
$result = some::code();
}
# do something after some::code
$_ += 42 for (@result, $result);
# finally return the correct value
if(!defined wantarray){
return;
}
elsif(wantarray){
return @result;
}
else {
return $result;
}
Now you can just write this instead:
use Context::Preserve;
return preserve_context { some::code() }
after => sub { $_ += 42 for @_ };
DESCRIPTION
Sometimes you need to call a function, get the results, act on the results, then return the result of the function. This is painful
because of contexts; the original function can behave different if it's called in void, scalar, or list context. You can ignore the
various cases and just pick one, but that's fragile. To do things right, you need to see which case you're being called in, and then call
the function in that context. This results in 3 code paths, which is a pain to type in (and maintain).
This module automates the process. You provide a coderef that is the "original function", and another coderef to run after the original
runs. You can modify the return value (aliased to @_) here, and do whatever else you need to do. "wantarray" is correct inside both
coderefs; in "after", though, the return value is ignored and the value "wantarray" returns is related to the context that the original
function was called in.
EXPORT
"preserve_context"
FUNCTIONS
preserve_context { original } [after|replace] => sub { after }
Invokes "original" in the same context as "preserve_context" was called in, save the results, runs "after" in the same context, then
returns the result of "original" (or "after" if "replace" is used).
If the second argument is "after", then you can modify @_ to affect the return value. "after"'s return value is ignored.
If the second argument is "replace", then modifying @_ doesn't do anything. The return value of "after" is returned from
"preserve_context" instead.
Run "preserve_context" like this:
sub whatever {
...
return preserve_context { orginal_function() }
after => sub { modify @_ };
}
or
sub whatever {
...
return preserve_context { orginal_function() }
replace => sub { return @new_return };
}
Note that there's no comma between the first block and the "after =>" part. This is how perl parses functions with the "(&@)" prototype.
The alternative is to say:
preserve_context(sub { original }, after => sub { after });
You can pick the one you like, but I think the first version is much prettier.
AUTHOR AND COPYRIGHT
Jonathan Rockway "<jrockway@cpan.org>"
Copyright (c) 2008 Infinity Interactive. You may redistribute this module under the same terms as Perl itself.
perl v5.16.2 2008-01-15 Context::Preserve(3)