02-06-2019
I made a mistake in the name of the variable on the output and fixed it, but it is better to correct the code from RudiC
Copy my code else and replace files places
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I have two text files, that need their data joining/concatenation. 'Paste' works for this.
But have an issue when there is mismatch in number of rows in each file.
E.g.
(main file) File1 - has 20 rows
File2 - has 30 rows.
Command 'paste file1 file2 > file3' joins all lines.
I want the... (4 Replies)
Discussion started by: sharath160
4 Replies
2. Shell Programming and Scripting
Hi All,
I am new to awk program. But i have got some assignment on awk.
The problem is:
i have two files file1 and file2. Both files have same structure. First i have to join both files on filed1,field2 and field3 and then for matching records i want to perform some calculation like:... (1 Reply)
Discussion started by: Jeetuibm
1 Replies
3. Shell Programming and Scripting
Hi i have a txt file in which i do a awk operation with ":" as field separator
A
B
C
D
ABC::2386.13:2386.13:3248234281995::+DPY:INT:3:N::::2:200.00:0.00:2010-05-12:CA:
::2:N::N:PH:00010031:0001+DPY:BAL:3:N::::3:1601.01:0.00:2010-05-12:XT::2:N:MR ... (1 Reply)
Discussion started by: mad_man12
1 Replies
4. Shell Programming and Scripting
First, thanks for the help in previous posts... couldn't have gotten where I am now without it!
So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following:
If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies
5. Shell Programming and Scripting
How do I use awk to replace the first hyphen of a specific record? (1 Reply)
Discussion started by: locoroco
1 Replies
6. Shell Programming and Scripting
I am trying to add 0393 value at 24th feild using the below command, but its adding at all the lines including header and trailer
Input file:
ZHV|2657|D0217001|T|TXU|Z|PAN|20131112000552||||OPER|
754|52479|
492|489|SP40|1014570286334|20131111|20131201|14355334|CHAMELON... (1 Reply)
Discussion started by: Aditya_001
1 Replies
7. Shell Programming and Scripting
Hello ,
I have three files :
sampleoutput1.txt has columns (in the following order) : hostname ; available patches , available packages
sampleoutput2.txt has columns (in the following order) : hostname ; patchwave ; BSID ; Application
sampleoutput3.txt has columns (in the following... (10 Replies)
Discussion started by: rahul2662
10 Replies
8. Shell Programming and Scripting
Trying to print the unique values in $2 before the -, currently the count is displayed. Hopefully, the below is close. Thank you :).
file
chr2:46603668-46603902 EPAS1-902|gc=54.3 253.1
chr2:211471445-211471675 CPS1-1205|gc=48.3 264.7
chr19:15291762-15291983 NOTCH3-1003|gc=68.8 195.8... (3 Replies)
Discussion started by: cmccabe
3 Replies
9. Shell Programming and Scripting
Hello All
I'm joining two files using Awk by Left outer join on the file 1
File 1
1 AA
2 BB
3 CC
4 DD
File 2
1 IND 100 200 300
2 AUS 400 500 600
5 USA 700 800 900 (18 Replies)
Discussion started by: venkat_reddy
18 Replies
10. Shell Programming and Scripting
Hi Folks,
I have a file with fields as follows which has last field in multiple lines. I would like to combine a line which has three fields with single field line for as shown in expected output. Please help.
INPUT
hname01 windows appnamec1eda_p1, ... (5 Replies)
Discussion started by: shunya
5 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)