Sponsored Content
Top Forums Shell Programming and Scripting replace multiple lines in multiple files Post 302238628 by demhyt on Sunday 21st of September 2008 08:47:47 AM
Old 09-21-2008
i think sed can solve your problem...

$cat file1.txt
one
two
three
four
five

$sed '3a
>testing
>again' file1.txt
one
two
three
testing
again
four
five

$

3a mean line3..in the line 4 and line 5 inserted the text testing and again...you can open gnulamp.com and search the sed tutorial...Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I replace multiple lines from different files

Suppose i have two files file1.txt Name : Raju Address:rt8pouououoiu City:tyretyeuetu file2.txt Address :28a The line "address:28a" in file2 has to get replaced in the address line of file1 .. The output should be Name :Raju Address:28a city :tyretyeuetu Please help me... (2 Replies)
Discussion started by: ranga27
2 Replies

2. Shell Programming and Scripting

Adding Multiple Lines to Multiple Files

Hello, I have three lines I need to add to hundreds of files. The files are all in the same format and contain the same information. I want to add the same information to the files. The new lines of information are similar. Here is an example of the three lines: line1: line2 =... (2 Replies)
Discussion started by: dayinthelife
2 Replies

3. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

4. Shell Programming and Scripting

Find and replace multiple lines

I have a section of text in file A, see below # falkdjf lkjadf lkjadf lkajdf lkajdf lkajdf lkjadf lkjadf 234.234.2.234 lkjlkjlk 234.234.3.234 # Only the first line with "# falkdjf lkjadf lkjadf" is unique in the file. The new section that I want to overwrite the old section above is in... (1 Reply)
Discussion started by: jyang72211
1 Replies

5. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

6. Shell Programming and Scripting

Replace multiple lines through sed

Hi All, I have a input file as sample below <this is not starting of file> record line1 line2 line3 end line4 line5 record line6 line7 line8 my requirement is this, i want to select a pattern between first record and end, whatever is written between first record and end. and... (0 Replies)
Discussion started by: adgangwar
0 Replies

7. Shell Programming and Scripting

Search & Replace: Multiple Strings / Multiple Files

I have a list of files all over a file system e.g. /home/1/foo/bar.x /www/sites/moose/foo.txtI'm looking for strings in these files and want to replace each occurrence with a replacement string, e.g. if I find: '#@!^\&@ in any of the files I want to replace it with: 655#@11, etc. There... (2 Replies)
Discussion started by: spacegoose
2 Replies

8. Shell Programming and Scripting

Replace a string with multiple lines

Hello Guys, I need to replace a string with multiple lines. For eg:- ABC,DEF,GHI,JKL,MNO,PQR,STU need to convert the above as below:- ABC,DEF, GHI1 GHI2 GHI3, JKL,MNO, PQR1 PQR2 PQR3, STU i have tried using code as:- (2 Replies)
Discussion started by: jassi10781
2 Replies

9. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

10. Shell Programming and Scripting

Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus, I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file. 1|ABC DEF|100|10 2|PQ RS T|200|20 3| UVWXYZ|300|30 4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies
BBE(1)																	    BBE(1)

NAME
bbe - binary block editor SYNOPSIS
bbe [options]... DESCRIPTION
bbe is a sed-like editor for binary files. It performs binary transformations on the blocks of input stream. OPTIONS
bbe accepts the following options: -b, --block=BLOCK Block definition. -e, --expression=COMMAND Add the COMMAND to the commands to be executed. -f, --file=script-file Add the contest of script-file to commands. -o, --output=name Write output to name instead of standard output. -s, --suppress Suppress normal output, print only block contents. -?, --help List all available options and their meanings. -V, --version Show version of program. BLOCK can be defined as: N:M Where N'th byte starts a M bytes long block (first byte is 0). :M Block length in input stream is M. /start/:M String start starts M bytes long block. /start/:/stop/ String start starts the block and block ends to string stop. /start/: String start starts the block and block will end at next occurence of start. Only the first start is included to the block. :/stop/ Block starts at the beginning of input stream (or at the end of previous block) and ends at the next occurrence of stop. String stop will be included to the block. Special value '$' of M means the end of stream. Default value for block is 0:$, meaning the whole input stream. Both start and stop strings are included to block. Nonprintable characters can be escaped as nn decimal xnn hexadecimal nnn octal Character '' can be escaped as '\'. Escape codes 'a','',' ',' ','v','f',' ' and ';' can also be used. Length (N and M) can be defined as decimal (n), hexadecimal (xn) or octal (0n) value. COMMAND SYNOPSIS
bbe has two type of commands: block and byte commands, both are allways related to current block. That means that the input stream outside of block remains untouched. Block commands D [n] Delete the n'th block. Without n, all found blocks are deleted from the output stream. I string Insert the string string before the block. A string Append the string string at the end of block. J n Skip n blocks before executing commands after this command. L n Leave all blocks unmodified starting from block number n. Affects only commands after this command. N Before printing a block, the file name in which the block starts is printed. F f Before printing a block, the input stream offset at the begining of the block is printed. f can be H, D or O for Hexadecimal, Deci- mal or Octal format of offset. B f Before printing a block, the block number is printed (first block == 1) f can be H, D or O for Hexadecimal, Decimal or Octal format of block number. > file Before printing a block, the contents of file file is printed. < file After printing a block, the contents of file file is printed. Byte commands n in byte commands is offset from the beginning of current block (starts from zero). r n string Replace bytes starting at position n with string string. i n string Insert string starting at position n. p format The contents of block is printed in format defined by format. format can have any of the formats H, D, O, A and B for Hexadecimal, Decimal, Octal, Asciii and Binary. s/search/replace/ Replace all occurrences of search with replace. y/source/dest/ Translate bytes in source to the corresponding bytes in dest. Source and dest must have equal length. d n m|* Delete m bytes starting from the offset n. If * is defined instead of m, then all bytes starting from n are deleted. c from to Convert bytes from format from to to. Currently supported formats are: BCD Binary coded decimal ASC Ascii j n Commands after the j-command are ignored for first n bytes of the block. l n Commands after the l-command are ignored from n'th byte of the block. w file Write bytes from the current block to file file. Commands before w-command have effect to what will be written. %B or %nB in file will be replaced by current block number. n in %nB is field length, leading zero in n causes the block number to be left padded with zeroes. & c Performs binary and with c. | c Performs binary or with c. ^ c Performs binary xor with c. ~ Performs binary negation. u n c All bytes from start of the block to offset n are replaced by c. f n c All bytes starting from offset n to end of the block are replaced by c. x Exchange the contents of nibbles (half an octet) of bytes. Nonvisible characters in strings can be escaped same way as in block definition strings. Character '/' in s and y commands can be any visi- ble character. Note that the D, A, I, F, B, c, s, i, y, p, <, > and d commands cause the length of input and output streams to be different. EXAMPLES
bbe -e "s/c:\temp\data1.txt/c:\temp\data2.txt/" file1 all occurences of "c: empdata1.txt" in file file1 are changed to "c: empdata2.txt" bbe -b 0420:16 -e "r 4 x12x4a" file1 Two bytes starting at fifth byte of a 16 byte long block starting at offset 0420 (octal) in file1 are changed to hexadecimal values 12 and 4a. bbe -b :16 -e "A x0a" file1 Newline is added after every block, block length is 16. SEE ALSO
sed(1). AUTHOR
Timo Savinen <tjsa@iki.fi> 2006-11-02 BBE(1)
All times are GMT -4. The time now is 09:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy