Sponsored Content
Top Forums Shell Programming and Scripting Grep a string and write a value to next line of found string Post 302547695 by dude2cool on Tuesday 16th of August 2011 11:07:41 AM
Old 08-16-2011
HTML Code:
gawk -F"=" -v x=$x -v y=$y      #Sets Field Separator to = and sets 2 
                                #variables to the values of x and y
 '/wf_xxxxxx/{                     #search for a line that has the pattern wf_xxxxxx
print;                              #print first line which is basically the line that    
                                          #contains wf_xxxxxx pattern
getline;                                # get next line
print $0x;                             # print the line with value of x
getline;print $0y;                   # repeat above for y
getline}1'   /tmp/yourfilename  # print rest of lines
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace all string instances found by find+grep

Hello all Im performing find + grep operation that looks like this : find . -name "*.dsp" | xargs grep -on Project.lib | grep -v ':0' and I like to add to this one liner the possibility to replace the string " Project.lib" that found ( more then once in file ) with "Example.lib" how can I do... (0 Replies)
Discussion started by: umen
0 Replies

2. Shell Programming and Scripting

grep to show date/time of file the string was found in.

I've seen several examples of grep showing the filename the string was found in, but what I really need is grep to show the file details in long format (like ls -l would). scenario is: grep mobile_number todays_files This will show me the string I'm after & which files they turn up in, but... (2 Replies)
Discussion started by: woodstock
2 Replies

3. Shell Programming and Scripting

Grep a string and print a string from the line below it

I know how to grep, copy and paste a string from a line. Now, what i want to do is to find a string and print a string from the line below it. To demonstrate: Name 1: ABC Age: 3 Sex: Male Name 2: DEF Age: 4 Sex: Male Output: 3 Male I know how to get "3". My biggest problem is to... (4 Replies)
Discussion started by: kingpeejay
4 Replies

4. Shell Programming and Scripting

grep on string and printing line after until another string has been found

Hello Everyone, I just started scripting this week. I have no background in programming or scripting. I'm working on a script to grep for a variable in a log file Heres what the log file looks like. The x's are all random clutter xxxxxxxxxxxxxxxxxxxxx START: xxxxxxxxxxxx... (7 Replies)
Discussion started by: rxc23816
7 Replies

5. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

6. UNIX for Dummies Questions & Answers

Append a string on the next line after a pattern string is found

Right now, my code is: s/Secondary Ins./Secondary Ins.\ 1/g It's adding a 1 as soon as it finds Secondary Ins. Primary Ins.: MEDICARE B DMERC Secondary Ins. 1: CONTINENTAL LIFE INS What I really want to achieve is having a 1 added on the next line that contain "Secondary Ins." It... (4 Replies)
Discussion started by: newbeee
4 Replies

7. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

8. Shell Programming and Scripting

Grep and replace with found string

Hi, I need to find all rows in 1st col of one file in another file (first occurrence) and replace the 1st col of first file with the grep result (the entire line). For example search AA from file 1 in file 2 and replace in file 1 by entire line found. File1 AA BB CC DD BB AA CC DDFile2 ... (2 Replies)
Discussion started by: ritakadm
2 Replies

9. Shell Programming and Scripting

Insert line based on found string

Hi All I'm trying to insert a new line at the before each comment line in a file. Comment lines start with '#-----' there are other comments with in lines but I don't want a new line there. Example file: blah blah #do not insert here #this is a comment blah #some more #another comment... (10 Replies)
Discussion started by: Mudshark
10 Replies

10. Shell Programming and Scripting

How to uppercase matching line when string found?

Hello, Could you please help me how to search the string in a file, and when found; change the existing line to uppercase in command line? I tried: ?whichcommand? -A "EXT" fileA | awk '{print tolower($0)}' | tee fileB tr command simply converts entire file to uppercase but this is not what... (4 Replies)
Discussion started by: baris35
4 Replies
SESSIONHANDLER(3)							 1							 SESSIONHANDLER(3)

The SessionHandler class

INTRODUCTION
SessionHandler is a special class that can be used to expose the current internal PHP session save handler by inheritance. There are seven methods which wrap the seven internal session save handler callbacks ($open, $close, $read, $write, $destroy, $gc and $create_sid). By default, this class will wrap whatever internal save handler is set as defined by the session.save_handler configuration directive which is usually $files by default. Other internal session save handlers are provided by PHP extensions such as SQLite (as $sqlite), Memcache (as $memcache), and Memcached (as $memcached). When a plain instance of SessionHandler is set as the save handler using session_set_save_handler(3) it will wrap the current save han- dlers. A class extending from SessionHandler allows you to override the methods or intercept or filter them by calls the parent class meth- ods which ultimately wrap the interal PHP session handlers. This allows you, for example, to intercept the $read and $write methods to encrypt/decrypt the session data and then pass the result to and from the parent class. Alternatively one might chose to entirely override a method like the garbage collection callback $gc. Because the SessionHandler wraps the current internal save handler methods, the above example of encryption can be applied to any internal save handler without having to know the internals of the handlers. To use this class, first set the save handler you wish to expose using session.save_handler and then pass an instance of SessionHandler or one extending it to session_set_save_handler(3). Please note the callback methods of this class are designed to be called internally by PHP and are not meant to be called from user-space code. The return values are equally processed internally by PHP. For more information on the session workflow, please refer ses- sion_set_save_handler(3). CLASS SYNOPSIS
SessionHandler SessionHandlerSessionHandlerInterface Methods o public bool SessionHandler::close (void ) o public string SessionHandler::create_sid (void ) o public bool SessionHandler::destroy (string $session_id) o public bool SessionHandler::gc (int $maxlifetime) o public bool SessionHandler::open (string $save_path, string $session_name) o public string SessionHandler::read (string $session_id) o public bool SessionHandler::write (string $session_id, string $session_data) Warning This class is designed to expose the current internal PHP session save handler, if you want to write your own custom save handlers, please implement the SessionHandlerInterface interface instead of extending from SessionHandler. CHANGELOG
+--------+--------------------------------------+ |Version | | | | | | | Description | | | | +--------+--------------------------------------+ | 5.5.1 | | | | | | | Added SessionHandler.create_sid(3). | | | | +--------+--------------------------------------+ Example #1 Using SessionHandler to add encryption to internal PHP save handlers. <?php class EncryptedSessionHandler extends SessionHandler { private $key; public function __construct($key) { $this->key = $key; } public function read($id) { $data = parent::read($id); return mcrypt_decrypt(MCRYPT_3DES, $this->key, $data, MCRYPT_MODE_ECB); } public function write($id, $data) { $data = mcrypt_encrypt(MCRYPT_3DES, $this->key, $data, MCRYPT_MODE_ECB); return parent::write($id, $data); } } // we'll intercept the native 'files' handler, but will equally work // with other internal native handlers like 'sqlite', 'memcache' or 'memcached' // which are provided by PHP extensions. ini_set('session.save_handler', 'files'); $handler = new EncryptedSessionHandler('mykey'); session_set_save_handler($handler, true); session_start(); // proceed to set and retrieve values by key from $_SESSION Note Since this class' methods are designed to be called internally by PHP as part of the normal session workflow, child class calls to parent methods (i.e. the actual internal native handlers) will return FALSE unless the session has actually been started (either automatically, or by explicit session_start(3). This is important to consider when writing unit tests where the class methods might be invoked manually. PHP Documentation Group SESSIONHANDLER(3)
All times are GMT -4. The time now is 07:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy