My actual input file was a bit more complicated, and was similar to this:
And the desired output is:
Before the reply from neutronscott came in, I managed to produce the desired output by piping it to a separate sed command to remove the unwanted newlines (which is somewhat similar to the solution suggested by Scrutinizer using paste):
Using the method suggested by neutronscott, I'm now producing the same output using:
It's actually slightly longer, but I prefer a single call to sed when possible.
Hi
It is possible with sed to print a pattern within a line matching regexp?
So, the line looks like : 19:00:00 blablablabla jobid 2345 <2>
the regexp is "jobid 2345" and the pattern is 56434.
That the code for find... (2 Replies)
How can I use sed to print rulers of x characters in length on my terminal?
For example, I want sed to print a 50-character rule.
sed '// p' ??
Thanks! (5 Replies)
I have file.txt
bob
jon
jones
gary
I want to print from the botton, up using sed.
gary
jones
jon
bob
Whats one command I can use to do this? Or will I have to construct a new file that would hold the original file in reverse and then print the reversed file? (3 Replies)
Hi folks,
Lets say I have the following text file:
name, lastname, 1234, name.lastname@test.com
name1, lastname1, name2.lastname2@test.com, 2345
name, 3456, lastname, name3.lastname3@test.com
4567, name, lastname, name4.lastname4@test.com
I now need the following output:
1234... (5 Replies)
Hello,
ı want to started shell programing. But first, I want to learn ssh code. How can I use this codes ( sed - awk - print ). How do codes work?
Thanks..
Best Wishes.. (1 Reply)
I am trying to figure out a one liner to toggle a flag variable. eg.
FLAG=0
Is there a way to use sed to toggle above example between 0 and 1. That is if run with flag set to zero it would change it to one if run again it would set it to zero.
I thought I had it figured but the... (6 Replies)
Hi
Imagine that I have a text file containing the following student's data:
student: john
group: A
sex: male
age: 25
student: alice
sex: female
age: 20
group: B
It is guarantee the details will start by "student:", and then followed by the sex, age and group in any order.
Is it... (2 Replies)
Dear all,
How can I print results (and of course, send this result to the text file) of sed command.
I mean, I want to know which lines of which files sed command has found.
For e.g, the result text file should contains:
file1.c:line 12
file2.h:line 14
file2.h:line 37
Please help me (10 Replies)
Hi
I am working with sed to get string replace and print all the lines.
Cat f1
<text1>
tag123 44412c232place1
text456-text=
tag12 44412c232place4
jjaa
TAG456 44412c232place1066dfdf
erer
..
i have used this command -
sed -n '/tag/ s#place#SomePlace#gp' f1
It gives me... (2 Replies)
Discussion started by: krsnadasa
2 Replies
LEARN ABOUT MOJAVE
data::optlist5.18
Data::OptList(3) User Contributed Perl Documentation Data::OptList(3)NAME
Data::OptList - parse and validate simple name/value option pairs
VERSION
version 0.109
SYNOPSIS
use Data::OptList;
my $options = Data::OptList::mkopt([
qw(key1 key2 key3 key4),
key5 => { ... },
key6 => [ ... ],
key7 => sub { ... },
key8 => { ... },
key8 => [ ... ],
]);
...is the same thing, more or less, as:
my $options = [
[ key1 => undef, ],
[ key2 => undef, ],
[ key3 => undef, ],
[ key4 => undef, ],
[ key5 => { ... }, ],
[ key6 => [ ... ], ],
[ key7 => sub { ... }, ],
[ key8 => { ... }, ],
[ key8 => [ ... ], ],
]);
DESCRIPTION
Hashes are great for storing named data, but if you want more than one entry for a name, you have to use a list of pairs. Even then, this
is really boring to write:
$values = [
foo => undef,
bar => undef,
baz => undef,
xyz => { ... },
];
Just look at all those undefs! Don't worry, we can get rid of those:
$values = [
map { $_ => undef } qw(foo bar baz),
xyz => { ... },
];
Aaaauuugh! We've saved a little typing, but now it requires thought to read, and thinking is even worse than typing... and it's got a bug!
It looked right, didn't it? Well, the "xyz => { ... }" gets consumed by the map, and we don't get the data we wanted.
With Data::OptList, you can do this instead:
$values = Data::OptList::mkopt([
qw(foo bar baz),
xyz => { ... },
]);
This works by assuming that any defined scalar is a name and any reference following a name is its value.
FUNCTIONS
mkopt
my $opt_list = Data::OptList::mkopt($input, \%arg);
Valid arguments are:
moniker - a word used in errors to describe the opt list; encouraged
require_unique - if true, no name may appear more than once
must_be - types to which opt list values are limited (described below)
name_test - a coderef used to test whether a value can be a name
(described below, but you probably don't want this)
This produces an array of arrays; the inner arrays are name/value pairs. Values will be either "undef" or a reference.
Positional parameters may be used for compatibility with the old "mkopt" interface:
my $opt_list = Data::OptList::mkopt($input, $moniker, $req_uni, $must_be);
Valid values for $input:
undef -> []
hashref -> [ [ key1 => value1 ] ... ] # non-ref values become undef
arrayref -> every name followed by a non-name becomes a pair: [ name => ref ]
every name followed by undef becomes a pair: [ name => undef ]
otherwise, it becomes [ name => undef ] like so:
[ "a", "b", [ 1, 2 ] ] -> [ [ a => undef ], [ b => [ 1, 2 ] ] ]
By default, a name is any defined non-reference. The "name_test" parameter can be a code ref that tests whether the argument passed it is
a name or not. This should be used rarely. Interactions between "require_unique" and "name_test" are not yet particularly elegant, as
"require_unique" just tests string equality. This may change.
The "must_be" parameter is either a scalar or array of scalars; it defines what kind(s) of refs may be values. If an invalid value is
found, an exception is thrown. If no value is passed for this argument, any reference is valid. If "must_be" specifies that values must
be CODE, HASH, ARRAY, or SCALAR, then Params::Util is used to check whether the given value can provide that interface. Otherwise, it
checks that the given value is an object of the kind.
In other words:
[ qw(SCALAR HASH Object::Known) ]
Means:
_SCALAR0($value) or _HASH($value) or _INSTANCE($value, 'Object::Known')
mkopt_hash
my $opt_hash = Data::OptList::mkopt_hash($input, $moniker, $must_be);
Given valid "mkopt" input, this routine returns a reference to a hash. It will throw an exception if any name has more than one value.
EXPORTS
Both "mkopt" and "mkopt_hash" may be exported on request.
AUTHOR
Ricardo Signes <rjbs@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2006 by Ricardo Signes.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
perl v5.18.2 2013-12-13 Data::OptList(3)