01-07-2009
ksh - adding a dynamic value to the front of a line
Hi Forum,
Im trying to write some code to read a file, take a certain dynamic value and write it back to the file at the front of every line.
For example, file.txt is:
SIMPLE=HELLO
CONFIDENTIAL=false
SENDER=false
REQUIRED=true
FEEDBACK=false
UPDATE=false
REQUIRED=false
MAPPING=true
SIMPLE=HELLO2
CONFIDENTIAL=false
SENDER=false
REQUIRED=true
FEEDBACK=false
UPDATE=false
REQUIRED=false
I want it to read the value of "SIMPLE", and return it back to the file at the front like so:
HELLO,SIMPLE=HELLO
HELLO,CONFIDENTIAL=false
HELLO,SENDER=false
HELLO,REQUIRED=true
HELLO,FEEDBACK=false
HELLO,UPDATE=false
HELLO,REQUIRED=false
HELLO,MAPPING=true
HELLO2,SIMPLE=HELLO2
HELLO2,CONFIDENTIAL=false
HELLO2,SENDER=false
HELLO2,REQUIRED=true
HELLO2,FEEDBACK=false
HELLO2,UPDATE=false
HELLO2,REQUIRED=false
Any help/ideas please?
thanks in advance
Ocelot
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
Is it possible to create a dynamic array in shell script. I am trying to get the list of logfiles that created that day and put it in a dynamic array. I am not sure about it. help me
New to scripting
Gundu (3 Replies)
Discussion started by: gundu
3 Replies
2. Shell Programming and Scripting
My requirement is to create a KSH to generate the SQL select statement in oracle with all the columns and optional where condition if given the table name as input to the program
Have any of you worked with a similar requirement? Can you give me some inputs?
Regards,
Kousikan (2 Replies)
Discussion started by: kousikan
2 Replies
3. Shell Programming and Scripting
dear pro-coders,
is there any command out there that takes out the front spaces from a string?
sample strings:
4 members
5 members
3 members
but it has to be like so:
4 members
5 members
3 members (3 Replies)
Discussion started by: pseudocoder
3 Replies
4. Shell Programming and Scripting
Adding a word in front of a word of each line.In that line only one word will be there.
pl help:( (4 Replies)
Discussion started by: Ramesh Vellanki
4 Replies
5. Shell Programming and Scripting
Hi everyon,
I am trying to search for a pattern in a file and add "//" to the begining of the file.
lets say i want to comment out a line from my codes. the line that should be commented out contains the word "reset". i need to search for the word "reset" and comment out that specific line. is... (5 Replies)
Discussion started by: ROOZ
5 Replies
6. Shell Programming and Scripting
Hi,
Can anybody help me how to add a word in front of a line in a file.Actually it is bit tricky to add a word. i will give a sample for this:
Input :
1110001 ABC DEF
1110001 EFG HIJ
1110001 KLM NOP
1110002 QRS RST
1110002 UVW XYZ
Output:
%HD% 1110001 ABC DEF
%DT% 1110001 EFG HIJ... (4 Replies)
Discussion started by: apjneeraj
4 Replies
7. Shell Programming and Scripting
Hello,
Did any one know how to use perl join line and add | in front
Input-->
timestamp=2009-11-10-04.55.20.829347;
a;
b;
c;
ddaa;
timestamp=2009-11-10-04.55.20.829347;
aa;
bb;
cc;
Output-->
... (2 Replies)
Discussion started by: happyday
2 Replies
8. Shell Programming and Scripting
hi,
i have stuff like
if ]; then
what does the x mean?
also, what does -z variable mean in an if statement>
thanks (8 Replies)
Discussion started by: JamesByars
8 Replies
9. Shell Programming and Scripting
Hi
I've one file full of paths of certain files and I want to add some extra file words in front of all the paths. for eg:
i have a file name test.txt which show some details only..
024_hd/044/0344eng.txt
035_bv/222/editor.jpg
here I want to add /usr/people/indiana/ infront of all the... (4 Replies)
Discussion started by: ratheeshp
4 Replies
10. Shell Programming and Scripting
I'm trying to convert this line:
to
\ with sed.
This is what I have so far:
sed -e 's/\]*\)\]/\\\\\/'
but this still gives me .
Any suggestions? (15 Replies)
Discussion started by: lehaste
15 Replies
LEARN ABOUT MOJAVE
boolean
boolean(3pm) User Contributed Perl Documentation boolean(3pm)
NAME
boolean - Boolean support for Perl
SYNOPSIS
use boolean;
do &always if true;
do &never if false;
do &maybe if boolean($value)->isTrue;
and:
use boolean ':all';
$guess = int(rand(2)) % 2 ? true : false;
do &something if isTrue($guess);
do &something_else if isFalse($guess);
and:
use boolean -truth;
die unless ref(42 == 42) eq 'boolean';
die unless ("foo" =~ /bar/) eq '0';
DESCRIPTION
Most programming languages have a native "Boolean" data type. Perl does not.
Perl has a simple and well known Truth System. The following scalar values are false:
$false1 = undef;
$false2 = 0;
$false3 = 0.0;
$false4 = '';
$false5 = '0';
Every other scalar value is true.
This module provides basic Boolean support, by defining two special objects: "true" and "false".
RATIONALE
When sharing data between programming languages, it is important to support the same group of basic types. In Perlish programming
languages, these types include: Hash, Array, String, Number, Null and Boolean. Perl lacks native Boolean support.
Data interchange modules like YAML and JSON can now "use boolean" to encode/decode/roundtrip Boolean values.
FUNCTIONS
This module defines the following functions:
true
This function returns a scalar value which will evaluate to true. The value is a singleton object, meaning there is only one "true"
value in a Perl process at any time. You can check to see whether the value is the "true" object with the isTrue function described
below.
false
This function returns a scalar value which will evaluate to false. The value is a singleton object, meaning there is only one "false"
value in a Perl process at any time. You can check to see whether the value is the "false" object with the isFalse function described
below.
boolean($scalar)
Casts the scalar value to a boolean value. If $scalar is true, it returns "boolean::true", otherwise it returns "boolean::false".
isTrue($scalar)
Returns "boolean::true" if the scalar passed to it is the "boolean::true" object. Returns "boolean::false" otherwise.
isFalse($scalar)
Returns "boolean::true" if the scalar passed to it is the "boolean::false" object. Returns "boolean::false" otherwise.
isBoolean($scalar)
Returns "boolean::true" if the scalar passed to it is the "boolean::true" or "boolean::false" object. Returns "boolean::false"
otherwise.
METHODS
Since true and false return objects, you can call methods on them.
$boolean->isTrue
Same as isTrue($boolean).
$boolean->isFalse
Same as isFalse($boolean).
USE OPTIONS
By default this module exports the "true", "false" and "boolean" functions.
The module also defines these export tags:
:all
Exports "true", "false", "boolean", "isTrue", "isFalse", "isBoolean"
-truth
You can specify the "-truth" option to override truth operators to return "boolean" values.
use boolean -truth;
print ref("hello" eq "world"), "
";
Prints:
boolean
"-truth" can be used with the other import options.
AUTHOR
Ingy doet Net <ingy@cpan.org>
COPYRIGHT
Copyright (c) 2007, 2008, 2010, 2011. Ingy doet Net.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
perl v5.12.4 2011-09-12 boolean(3pm)