Sponsored Content
Top Forums Shell Programming and Scripting setter and getter functions for file manipulation with sed Post 302602873 by Toorop on Tuesday 28th of February 2012 02:33:44 PM
Old 02-28-2012
setter and getter functions for file manipulation with sed

Hi,

I would really appreciate some help, I couldn't nail my problem:
I would like to create some setter and getter functions to make my life easier.

my sample file contains:
keyword - some tabs - value - semicolon
number 12.1;
float .3;
double 12;
real 12.2324;
stuff .234;
decimal 15.;
fruit apple;
veg carrot;
vegetable tomato;
my functions:
Code:
setNumber()
{
    sed -i '/^'$1'/s/[0-9][0-9]*\.*[0-9]*/'$2'/g' file
}

getNumber()
{
...
}

setParam()
{
...
}

getParam()
{
...
}

The setNumber works with all the different number forms, except the one which starts with a decimal point. Unfortunately, I'm not an expert in text manipulation.

The getters need to return the key value.

Maybe the two setter and getter functions can be merged, but I'm curious how to accomplish the get/set number as well.

Desired functionality:
setNumber number 1.1
setNumber float 1.2
setNumber double 1.3
setNumber real 1.4
setNumber stuff 1.5
setNumber decimal 1.6
setParam veg pumpkin
setParam vegetable pepper
setParam fruit cherry
number 1.1;
float 1.2;
double 1.3;
real 1.4;
stuff 1.5;
decimal 1.6;
fruit cherry;
veg pumpkin ;
vegetable pepper;
Thanks!
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

file name Manipulation using sed

Hi, I have a file name, for which I want to strip out the first bit and leave the rest... So I want to take the file name .lockfile-filename.10001 ,strip it and have only filename.10001 ... Thanking you all inadvance, Zak (6 Replies)
Discussion started by: Zak
6 Replies

2. Shell Programming and Scripting

How to use sed for string manipulation

Hi, I would like to know How to use use sed for manipulating string for the following situation. Basically my objective is to check validity of the filename in my shell script. I am getting a parameter like this for my shell script. Check my folder is having some space. $1=/root/krishna... (2 Replies)
Discussion started by: hikrishn
2 Replies

3. Shell Programming and Scripting

File manipulation with AWK and SED

Hello How do i check that correct input files are used while using AWk and SED for file manipulation? e.g awk '/bin/ {print $0 }' shell.txt sed 's/hp/samsung/' printers.txt how do i ensure that the correct input files I am working with are used? (5 Replies)
Discussion started by: Pauline mugisha
5 Replies

4. Shell Programming and Scripting

SED/AWK file read & manipulation

I have large number of data files, close to 300 files, lets say all files are same kind and have extension .dat , each file have mulitple lines in it. There is a unique line in each file containing string 'SERVER'. Right after this line there is another line which contain a string 'DIGIT=0',... (4 Replies)
Discussion started by: sal_tx
4 Replies

5. Shell Programming and Scripting

Manipulation with the string using sed

hello All, When I run find command on certain directory I may get one of the following output depending on configuration A. ./rel/prod/libpam.a B. ./rel/fld/libpam.a C. ./deb/detail/libpam.a D. ./deb/err/libpam.a I want to get output as below A. rel/prod B.... (2 Replies)
Discussion started by: anand.shah
2 Replies

6. Shell Programming and Scripting

sed flat file manipulation

Hello, I have a large flat file where i need to change data in columns 131-133 based on what is in columns 172-173. I am not sure if I need to read the file line by line and make the change or if I can do this in a single statement. thank you (3 Replies)
Discussion started by: gblmin
3 Replies

7. Programming

Simplify setter and getter of java class

I am trying to verify my understanding on setter and getter on java class with this example: //MaximumFinder2.java import java.util.Scanner; public class MaximumFinder2 { public static void main (String args) { Scanner input = new Scanner(System.in); ... (6 Replies)
Discussion started by: yifangt
6 Replies

8. Shell Programming and Scripting

sed for string manipulation

I have a file which contains contents like below proxy.config.cluster.mc_group_addr 224.0.1.37 proxy.config.log.logging_enabled 3 proxy.config.log.squid_log_enabled 1 Need to modify to 'proxy.config.cluster.mc_group_addr': '224.0.1.37' 'proxy.config.log.logging_enabled': '3'... (10 Replies)
Discussion started by: esham
10 Replies

9. UNIX for Beginners Questions & Answers

File manipulation place 0 before the number using sed

I'm new with sed, and i am really confused with slashes, backslashes, parentheses, I've tried reading some beginner's guide, but still trouble fixing this problem, do you have any tips where or what to read to learn more about sed? can you also help me with my problem? Note: I was tasked to use... (4 Replies)
Discussion started by: akopocpoypoy
4 Replies
AGGREGATE_INFO(3)							 1							 AGGREGATE_INFO(3)

aggregate_info - Gets aggregation information for a given object

SYNOPSIS
array aggregate_info (object $object) DESCRIPTION
Gets the aggregation information for the given $object. PARAMETERS
o $object - RETURN VALUES
Returns the aggregation information as an associative array of arrays of methods and properties. The key for the main array is the name of the aggregated class. EXAMPLES
Example #1 Using aggregate_info(3) <?php class Slicer { var $vegetable; function Slicer($vegetable) { $this->vegetable = $vegetable; } function slice_it($num_cuts) { echo "Doing some simple slicing "; for ($i=0; $i < $num_cuts; $i++) { // do some slicing } } } class Dicer { var $vegetable; var $rotation_angle = 90; // degrees function Dicer($vegetable) { $this->vegetable = $vegetable; } function dice_it($num_cuts) { echo "Cutting in one direction "; for ($i=0; $i < $num_cuts; $i++) { // do some cutting } $this->rotate($this->rotation_angle); echo "Cutting in a second direction "; for ($i=0; $i < $num_cuts; $i++) { // do some more cutting } } function rotate($deg) { echo "Now rotating {$this->vegetable} {$deg} degrees "; } function _secret_super_dicing($num_cuts) { // so secret we cannot show you ;-) } } $obj = new Slicer('onion'); aggregate($obj, 'Dicer'); print_r(aggregate_info($obj)); ?> The above example will output: Array ( [dicer] => Array ( [methods] => Array ( [0] => dice_it [1] => rotate ) [properties] => Array ( [0] => rotation_angle ) ) ) As you can see, all properties and methods of the Dicer class have been aggregated into our new object, with the exception of the class constructor and the method _secret_super_dicing SEE ALSO
aggregate(3), aggregate_methods(3), aggregate_methods_by_list(3), aggregate_methods_by_regexp(3), aggregate_properties(3), aggregate_prop- erties_by_list(3), aggregate_properties_by_regexp(3), deaggregate(3). PHP Documentation Group AGGREGATE_INFO(3)
All times are GMT -4. The time now is 07:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy