Sponsored Content
Top Forums Shell Programming and Scripting Help with replace data content Post 302576729 by balajesuri on Saturday 26th of November 2011 01:15:18 AM
Old 11-26-2011
A solution in Perl.

Code:
#! /usr/bin/perl
use warnings;
use strict;

my (@x, @y, $line);
open SOURCE, "< source.txt";
for $line (<SOURCE>) {
    if ($line =~ /^# >/) {
        @x = split /\s+/, $line;
        $x[1] =~ s/>//;
        open DEST, ">> output.txt";
        print DEST "$line";
        close DEST;
        next;
    }
    else {
        @y = split /\t/, $line;
        $y[0] =~ s/$y[0]/$x[1]/;
        open DEST, ">> output.txt";
        print DEST join "\t", @y;
        close DEST;
    }
}
close SOURCE;

source.txt:
------------------
# >length=1
seq program data 909 1992
seq program record 909 1190
# >length=2
seq program data 909 1992
seq program record 909 1190

output.txt:
-------------------
# >length=1
length=1 program data 909 1992
length=1 program record 909 1190
# >length=2
length=2 program data 909 1992
length=2 program record 909 1190
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace a variable content

Hi, variable1="This is a car" Now I want to replace the content of variable1, "car" to "dog". Is there any simple command I can use. Thanks. Joseph (4 Replies)
Discussion started by: josephwong
4 Replies

2. Shell Programming and Scripting

How to replace a line content

Hi Experts, I have binary files contain an ID Line as: : : $Header: FNDSCMON.fmb 115.6 2000/01/11 10:26:10 pkm ship$ : : where the ID Line format is: $Header: <File_Name> <Version> <Last_update_date_time> pkm ship$ In this Example: File_Name = FNDSCMON.fmb Version = 115.6... (13 Replies)
Discussion started by: victorcheung
13 Replies

3. Shell Programming and Scripting

search and replace the content

Hi All,sorry for inconvience....please find the attachement for my question i am unable to paste the question here....please help me in slving thisthanksk.k (4 Replies)
Discussion started by: G.K.K
4 Replies

4. Shell Programming and Scripting

Extract specific data content from a long list of data

My input: Data name: ABC001 Data length: 1000 Detail info Data Direction Start_time End_time Length 1 forward 10 100 90 1 forward 15 200 185 2 reverse 50 500 450 Data name: XFG110 Data length: 100 Detail info Data Direction Start_time End_time Length 1 forward 50 100 50 ... (11 Replies)
Discussion started by: patrick87
11 Replies

5. Shell Programming and Scripting

Replace data of one column with data on other file corresponding to transaction ID matched

Hi All, I have two files one of which having some mobile numbers and corresponding value whose sample content as follows: 9058629605,8.0 9122828964,30.0 And in second file complete details of all mobile numbers and sample content as follows and delimeter used is comma(,): ... (8 Replies)
Discussion started by: poweroflinux
8 Replies

6. Shell Programming and Scripting

Help with replace duplicate content

Input file: CCNI data564_input1 264 CORO1A data564_input2 155 ABC-B data17_input1 3466 ABC-B data17_input2 1133 ABC-B data17_input3 2162 ABC-B data17_input4 2019 HNRNPA2B1 data95_input1 101 HNRNPA2B1 data95_input2 340 IFITM1 data105_input2 291 IFITM2 data105_input1 505... (3 Replies)
Discussion started by: cpp_beginner
3 Replies

7. Shell Programming and Scripting

Sed: replace content from file with the content from file

Hi, I am having trouble while using 'sed' with reading files. Please help. I have 3 files. File A, file B and file C. I want to find content of file B in file A and replace it by content in file C. Thanks a lot!! Here is a sample of my question. e.g. (file A: a.txt; file B: b.txt; file... (3 Replies)
Discussion started by: dirkaulo
3 Replies

8. Shell Programming and Scripting

Help with replace all the content within ()

Hi, Below is my input file : AAAG(12) TC(14) AACCCT(66) AACCCT(30) AACCCT(18) AACCCT(48) TCTG(12) TCTG(20) TCTG(16) AC(12) AC(12) TCTG(16) TCTG(12) AC(12) AC(12) AC(12) AC(26) AC(14) AGTG(12) AC(24) AGTG(12) TCC(12) Desired output : AAAG TC AACCCT AACCCT AACCCT AACCCT TCTG TCTG... (4 Replies)
Discussion started by: perl_beginner
4 Replies

9. Shell Programming and Scripting

Mysql Content Replace

I have a wordpress site. I need add "post_title" to all my "post_content" mysql field. Thanks. my content: Free <b>Online Tips</b> output:Free post_title <b>Online Tips</b>: This code does not work: UPDATE wp_posts SET post_content = REPLACE ( post_content, 'Free <b>Online... (0 Replies)
Discussion started by: tara123
0 Replies

10. Shell Programming and Scripting

Replace Content

Hello all ; ) I'got a file1 with a lot of emails like : fistname.lastname@domaine1.comAnd another file2 with emails like fistname.lastname@domaine2.ct.netI need a shell script that will read each line from the file1 and try to find if in file2 the fistname.lastname exist. If yes, the... (1 Reply)
Discussion started by: Aswex
1 Replies
RBOT-REMOTE(1)						       rbot-remote man page						    RBOT-REMOTE(1)

NAME
rbot-remote - IRC bot written in ruby SYNOPSIS
rbot-remote {{[-u USER] | [--user USER]} {[-p PASSWORD] | [--password PASSWORD]}} [{[-d DEST] | [--destination DEST]} {[-r DRB_URI] | [--uri DRB_URI]} {[-h] | [--help]} {[-a] | [--about]}] DESCRIPTION
rbot-remote is a proof-of-concept example for rbot druby-based api. This program reads lines of text from the standard input and sends them to a specified irc channel or user via rbot. Make sure you have the remotectl plugin loaded and assigned the needed rights to the user before use. OPTIONS
This program follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. -u USER, --user USER Remote user. -p PASSWORD, --password PASSWORD Remote user password. -d DEST, --destination DEST Destination for message (user or channel). -r DRB_URI, --uri DRB_URI Rbot url. -h, --help Show summary of options. -a, --about Tell what it's all about. VERSION
This manual page was written by Marc Dequenes (Duck) Duck@DuckCorp.org for the Debian(TM) system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 3 or any later version published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. AUTHORS
Marc Dequenes <Duck@DuckCorp.org> Debian(TM) package maintainer Giuseppe Bilotta <giuseppe.bilotta@gmail.com> rbot-remote maintainer COPYRIGHT
Copyright (C) 2004-2009 Marc Dequenes (Duck) Copyright (C) 2010 Giuseppe Bilotta rbot 0.9.15 20100701 RBOT-REMOTE(1)
All times are GMT -4. The time now is 08:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy