![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| find text but replace a text beside it | The One | Shell Programming and Scripting | 4 | 09-02-2008 03:13 AM |
| bash find and remove text | Movomito | Shell Programming and Scripting | 5 | 04-05-2008 01:48 PM |
| A simple find and replace without using any regex (bash) | srikanths | Shell Programming and Scripting | 2 | 03-18-2008 08:08 AM |
| Find and replace text PLEASE HELP | bobo | UNIX for Dummies Questions & Answers | 6 | 01-12-2006 05:16 PM |
| Find and replace text | bobo | UNIX for Dummies Questions & Answers | 1 | 01-12-2006 01:17 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
find, copy and replace text in bash or sh
here is my prob ..
i have a very large text files and i need to locate specific lines, copy them and then replace a single word in the replaced text example find all lines that contain '/etc', copy the line immediately below (not at the end of the file) and then replace '/etc' with '/root' in the new line old text: rsync --delete -avpz xxx.xxx.xxx.xxx:/var /usr/backup/123 > /usr/backup.log rsync --delete -avpz xxx.xxx.xxx.xxx:/usr/local/etc /usr/backup/123/loc > /usr/backup.log rsync --delete -avpz xxx.xxx.xxx.xxx:/etc /usr/backup/123 > /usr/backup.log new: rsync --delete -avpz xxx.xxx.xxx.xxx:/var /usr/backup/123 > /usr/backup.log rsync --delete -avpz xxx.xxx.xxx.xxx:/usr/local/etc /usr/backup/123/loc > /usr/backup.log rsync --delete -avpz xxx.xxx.xxx.xxx:/etc /usr/backup/123 > /usr/backup.log rsync --delete -avpz xxx.xxx.xxx.xxx:/root /usr/backup/123 > /usr/backup.log i hope my request for help is not too convoluted .. thank you so much in advance!!! j |
|
||||
|
Hi, You may try perl:
#! /usr/bin/perl Code:
open FH,"<a.txt";
@arr=<FH>;
map {tr/\n//d} @arr;
for($i=0;$i<=$#arr;$i++){
print $arr[$i],"\n";
if ($arr[$i]=~m/etc/){
print $arr[$i+1],"\n" if ($i+1 <= $#arr);
$arr[$i+1]=~s/etc/root/ if ($i != $#arr);
}
}
close FH;
|
![]() |
| Bookmarks |
| Tags |
| bash, copy, find, replace |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|