Sponsored Content
Top Forums Shell Programming and Scripting How to substract selective values in multi row, multi column file (using awk or sed?) Post 302714813 by scottaazz on Friday 12th of October 2012 05:54:50 PM
Old 10-12-2012
take a look at the getline man page.

Code:
BEGIN {OFS = ",";}
{
    nLine1 = split($0, Line1, ",");
    getline;
    $1 = Line1[1]; $3 = Line1[3];
    for (i=4;i<=nLine1;i++) $i = sprintf("(%s-%s)",Line1[i],$i);
    print;
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

multi-file multi-edit

Good day! I am trying to learn how to use the "sed" editor, to perform multiple edits on multiple files in multiple directories. I have one script that tries to call up each file and process it according to the edits listed in a second script. I am using a small input text to test these, at... (12 Replies)
Discussion started by: kielitaide
12 Replies

2. Shell Programming and Scripting

Sorting multi-column values from a specific file

Hi, all. I need a shell script which gathers data from a remote XML file and then displays it according to my needs.. I need this for my job due to the fact that I need to keep track price changes of euro, usd, gold, etc. The XML file I am talking about is located at this page: cnnturk dot... (4 Replies)
Discussion started by: canimsin
4 Replies

3. UNIX for Dummies Questions & Answers

sed insert content of file.txt to multi files

Ive this sed & find command find /home/www/ -name footer.php -exec sed -i 's/<\/body>/file.txt\n<\/body>/' what I need to place content of file.txt before </body> in all footer.php files file.txt content is google analytic script which is like 7 lines any help to adjust my command to... (2 Replies)
Discussion started by: xmoe
2 Replies

4. Shell Programming and Scripting

Multi-line filtering based on multi-line pattern in a file

I have a file with data records separated by multiple equals signs, as below. ========== RECORD 1 ========== RECORD 2 DATA LINE ========== RECORD 3 ========== RECORD 4 DATA LINE ========== RECORD 5 DATA LINE ========== I need to filter out all data from this file where the... (2 Replies)
Discussion started by: Finja
2 Replies

5. Shell Programming and Scripting

Gawk - to extract values from multi lined file

Hi, I am new to awk and trying to extract some specific fields from the a large file. Can you please help me to write gawk code displaying the out put in the below format: Desired Output: name fallback_ip member member www-trymps.extlb.plstry.com-pool-1 180.254.112.50 ... (4 Replies)
Discussion started by: pratheeshp
4 Replies

6. Shell Programming and Scripting

Gawk - to extract values from multi lined file -I

Hi, Request your help in getting help with the below text formatting using awk. I am still learning awk and your help here is appreciated. Thanks in advance. Desireoutput ---------------- Virtual Pool Destination Profile Profile Profile Profile 1. virtual-1 pool-1 212.254.110.174:https... (2 Replies)
Discussion started by: pratheeshp
2 Replies

7. Shell Programming and Scripting

Selective Replace awk column values

Hi, I have the following data: 2860377|"DATA1"|"DATA2"|"65343"|"DATA2"|"DATA4"|"11"|"DATA5"|"DATA6"|"65343"|"DATA7"|"0"|"8"|"1"|"NEGATIVE" 32340377|"DATA1"|"DATA2"|"65343"|"DATA2"|"DATA4"|"11"|"DATA5"|"DATA6"|"65343"|"DATA7"|"0"|"8"|"1"|"NEG-DID"... (3 Replies)
Discussion started by: sdohn
3 Replies

8. Shell Programming and Scripting

Replacing lines matching a multi-line pattern (sed/perl/awk)

Dear Unix Forums, I am hoping you can help me with a pattern matching problem. What am I trying to do? I want to replace multiple lines of a text file (that match a multi-line pattern) with a single line of text. These patterns can span several lines and do not always have the same number of... (10 Replies)
Discussion started by: thefang
10 Replies

9. Programming

Multi head/multi window hello world

I am trying to write a large X app. I have successfully modified my xorg.conf to setup 4 monitors on an NVIDIA Quatro5200. I am trying to modify a simple hello world application to open a window on three of the four monitors. depending on the changes to loop the window creation section and event... (2 Replies)
Discussion started by: advorak
2 Replies

10. Programming

DB2 Query -Convert multi values from column to rows

Hi Team I am using DB2 artisan tool and struck to handle multi values present in columns that are comma(,) separated. I want to convert those column values in separate rows . For example : Column 1 Column2 Jan,Feb Hold,Sell,Buy Expected Result Column1 ... (3 Replies)
Discussion started by: Perlbaby
3 Replies
STREAM_FILTER_REGISTER(3)						 1						 STREAM_FILTER_REGISTER(3)

stream_filter_register - Register a user defined stream filter

SYNOPSIS
bool stream_filter_register (string $filtername, string $classname) DESCRIPTION
stream_filter_register(3) allows you to implement your own filter on any registered stream used with all the other filesystem functions (such as fopen(3), fread(3) etc.). PARAMETERS
o $filtername - The filter name to be registered. o $classname - To implement a filter, you need to define a class as an extension of php_user_filter with a number of member functions. When performing read/write operations on the stream to which your filter is attached, PHP will pass the data through your filter (and any other filters attached to that stream) so that the data may be modified as desired. You must implement the methods exactly as described in php_user_filter - doing otherwise will lead to undefined behaviour. RETURN VALUES
Returns TRUE on success or FALSE on failure. stream_filter_register(3) will return FALSE if the $filtername is already defined. EXAMPLES
Example #1 Filter for capitalizing characters on foo-bar.txt stream The example below implements a filter named strtoupper on the foo-bar.txt stream which will capitalize all letter characters writ- ten to/read from that stream. <?php /* Define our filter class */ class strtoupper_filter extends php_user_filter { function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { $bucket->data = strtoupper($bucket->data); $consumed += $bucket->datalen; stream_bucket_append($out, $bucket); } return PSFS_PASS_ON; } } /* Register our filter with PHP */ stream_filter_register("strtoupper", "strtoupper_filter") or die("Failed to register filter"); $fp = fopen("foo-bar.txt", "w"); /* Attach the registered filter to the stream just opened */ stream_filter_append($fp, "strtoupper"); fwrite($fp, "Line1 "); fwrite($fp, "Word - 2 "); fwrite($fp, "Easy As 123 "); fclose($fp); /* Read the contents back out */ readfile("foo-bar.txt"); ?> The above example will output: LINE1 WORD - 2 EASY AS 123 Example #2 Registering a generic filter class to match multiple filter names. <?php /* Define our filter class */ class string_filter extends php_user_filter { var $mode; function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { if ($this->mode == 1) { $bucket->data = strtoupper($bucket->data); } elseif ($this->mode == 0) { $bucket->data = strtolower($bucket->data); } $consumed += $bucket->datalen; stream_bucket_append($out, $bucket); } return PSFS_PASS_ON; } function onCreate() { if ($this->filtername == 'str.toupper') { $this->mode = 1; } elseif ($this->filtername == 'str.tolower') { $this->mode = 0; } else { /* Some other str.* filter was asked for, report failure so that PHP will keep looking */ return false; } return true; } } /* Register our filter with PHP */ stream_filter_register("str.*", "string_filter") or die("Failed to register filter"); $fp = fopen("foo-bar.txt", "w"); /* Attach the registered filter to the stream just opened We could alternately bind to str.tolower here */ stream_filter_append($fp, "str.toupper"); fwrite($fp, "Line1 "); fwrite($fp, "Word - 2 "); fwrite($fp, "Easy As 123 "); fclose($fp); /* Read the contents back out */ readfile("foo-bar.txt"); ?> The above example will output: LINE1 WORD - 2 EASY AS 123 SEE ALSO
stream_wrapper_register(3), stream_filter_append(3), stream_filter_prepend(3). PHP Documentation Group STREAM_FILTER_REGISTER(3)
All times are GMT -4. The time now is 01:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy