Sponsored Content
Top Forums Shell Programming and Scripting using sed/awk to replace a block of text in a file? Post 302577533 by CarloM on Tuesday 29th of November 2011 09:41:10 AM
Old 11-29-2011
Try
Code:
sed 's/The.*dog/whatever/' inputfile

EDIT: Note that .* will match the longest available string though, e.g.
Code:
# echo "The quick brown fox fell over the dog" | sed 's/The.*dog/whatever/'
whatever
# echo "The quick brown fox fell over the dog and some other dogs and cats" | sed 's/The.*dog/whatever/'
whatevers and cats

This User Gave Thanks to CarloM For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace a range of text with sed or awk?

Howdy! I'm trying to automate editing of a configuration file (custom.conf for GDM). I need to find every line between a line that starts with "" and the next line that starts with "", I want to preserve that line, but then delete all the lines in that configuration section and then insert... (3 Replies)
Discussion started by: TXTad
3 Replies

2. Shell Programming and Scripting

pattern replace inside text file using sed

Hi, I have a situation where I want to replace some occurrences of ".jsp" into ".html" inside a text file. For Example: If a pattern found like <a href="http://www.mysite.com/mypage.jsp"> it should be retained. But if a pattern found like <a href="../mypage.jsp"> it should be changed to... (4 Replies)
Discussion started by: meharo
4 Replies

3. Shell Programming and Scripting

replace block of text with content of another file

Hello, file1: not to be changed not to be changed <start> old stuff old stuff old stuff <end> not to be changed not to be changed file2: new text new text desired output: (3 Replies)
Discussion started by: ripat
3 Replies

4. Shell Programming and Scripting

How to replace multiple text in a file using sed

can anyone please help me in the below scenario: File1: Hello1 Hello1 i want to use sed to replace multiple occurances of Hello1 in file 1 to welcome. Thanks a ton for the help (9 Replies)
Discussion started by: amithkhandakar
9 Replies

5. Shell Programming and Scripting

Delete first block of text with sed/awk

Hello, guys! "filename" has blocks with three lines each in this fashion: 93909286 #verified has one bug 10909286 #unverified pending 10909286 #unverified pendingThe above example has duplicate blocks, and I have tried using sed to remove just one block... The... (2 Replies)
Discussion started by: teresaejunior
2 Replies

6. UNIX for Dummies Questions & Answers

Use sed to replace but only in a specific column of the text file

Hi, I would like to use sed to replace NA to x ('s/NA/x/g'), but only in the 5th column of the space delimited text file, nowhere else. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

7. UNIX for Dummies Questions & Answers

Using sed to replace / in text file

Hi, I want to use sed to replace " /// " with "///" in a text file. However I am getting error messages when I use sed 's/ /// /////g' input.txt > output.txt. How do I go about doing this in sed? Input: 219518_s_at 0.000189 ELL3 / SERINC4 Output: 219518_s_at 0.000189 ELL3/SERINC4 (5 Replies)
Discussion started by: evelibertine
5 Replies

8. Shell Programming and Scripting

Pattern replace from a text file using sed

I have a sample text format as given below <Text Text_ID="10155645315851111_10155645333076543" From="460350337461111" Created="2011-03-16T17:05:37+0000" use_count="123">This is the first text</Text> <Text Text_ID="10155645315851111_10155645317023456" From="1626711840902323"... (3 Replies)
Discussion started by: my_Perl
3 Replies

9. Debian

Using awk and sed to replace text

Good Day Every one I have a problem finding and replacing text in some large files that will take a long time to manually edit. Example text file looks like this #Example Large Text File unix linux dos squid bind dance bike car plane What im trying to do is to edit all the... (4 Replies)
Discussion started by: linuxjunkie
4 Replies

10. UNIX for Beginners Questions & Answers

Help with awk or sed Command to Replace Text in Files

Hello Everyone, I have many files like so: file1.txt file2.txt file3.txt Within each file I have many lines of random text separated by commas like so: abcAAA,123,defAA,456777,ghiA,789 jklB,101,mnoBBB,11211,pqrB,13111 stuCC,415,vwxCCCC,161,yzaC,718 I am trying to use SED or AWK to... (4 Replies)
Discussion started by: D3U5X
4 Replies
HASH(3) 								 1								   HASH(3)

hash - Generate a hash value (message digest)

SYNOPSIS
string hash (string $algo, string $data, [bool $raw_output = false]) DESCRIPTION
PARAMETERS
o $algo - Name of selected hashing algorithm (e.g. "md5", "sha256", "haval160,4", etc..) o $data - Message to be hashed. o $raw_output - When set to TRUE, outputs raw binary data. FALSE outputs lowercase hexits. RETURN VALUES
Returns a string containing the calculated message digest as lowercase hexits unless $raw_output is set to true in which case the raw binary representation of the message digest is returned. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.4.0 | | | | | | | The tiger algorithm now uses big-endian byte | | | ordering. See also example below. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 A hash(3) example <?php echo hash('ripemd160', 'The quick brown fox jumped over the lazy dog.'); ?> The above example will output: ec457d0a974c48d5685a7efa03d137dc8bbde7e3 Example #2 Calculate pre PHP-5.4 tiger hashes with PHP-5.4 and higher <?php function old_tiger($data = "", $width=192, $rounds = 3) { return substr( implode( array_map( function ($h) { return str_pad(bin2hex(strrev($h)), 16, "0"); }, str_split(hash("tiger192,$rounds", $data, true), 8) ) ), 0, 48-(192-$width)/4 ); } echo hash('tiger192,3', 'a-string'), PHP_EOL; echo old_tiger('a-string'), PHP_EOL; ?> Output of the above example in PHP 5.3: 146a7492719b3564094efe7abbd40a7416fd900179d02773 64359b7192746a14740ad4bb7afe4e097327d0790190fd16 Output of the above example in PHP 5.4: 64359b7192746a14740ad4bb7afe4e097327d0790190fd16 146a7492719b3564094efe7abbd40a7416fd900179d02773 SEE ALSO
hash_file(3), hash_hmac(3), hash_init(3), md5(3), sha1(3). PHP Documentation Group HASH(3)
All times are GMT -4. The time now is 02:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy