Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8532193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:39:29+00:00 2026-06-11T09:39:29+00:00

I want to edit a file in place (substitute a column value) based on

  • 0

I want to edit a file in place (substitute a column value) based on a value in another column in same file. I don’t want to redirect the output after substitution to another file but rather would want to edit the file in place. Specifically need this because file which needs to be edited will be accessed by no of programs simultaneously and in-place editing is must for this

I tried code below. but this is again writing to input file line by line

#!/usr/bin/perl -w

open(FILEIN, "/dummy/chaat/h2") || die("Cannot open file");
@file = <FILEIN>;
seek FILEIN, 0, 0;

foreach $file (@file) {
    @field = split(/\|/, $file);
    print $field[8] . "\n";
    if ($field[8] eq "ROBERT") {
        $file =~ s/JAMES/FUDIK/g;
        print FILEIN $file;
    }
}

My sample records are as shown below. Here I want to do inline editing of this. if field 8 is ROBERT then substitute JAMES with FUDIK in field 7

Change|sinmg|ewfewf|ewfew|def|fdfd|JAMES|rewr|ROBERT|dsf|fe
Change|sinmg|ewfewf|ewfew|def|JAMES|fewf|rewr|BEASLEY|dsf|fe

I would appreciate any help on this

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:39:30+00:00Added an answer on June 11, 2026 at 9:39 am

    This is a perl one-liner:

    perl -F'\|' -i -lape 'if ($F[8] eq "ROBERT") { s/JAMES/FUDIK/g }' /dummy/chaat/h2
    

    The -i option will do the in-place edit. You may wish to restrict the substitution to avoid partial matches, e.g.:

    s/(?<=\|)JAMES(?=\|)/FUDIK/g
    

    Or you can use the -n switch instead of -p and do

    s/JAMES/FUDIK/g for @F } print join "|", @F;
    

    You should be aware that this in-place edit is in fact writing a new file, and copying over the old. If you want to avoid this, you need to do some serious juggling, and probably lock the file during writing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to edit .vimrc file from Vim and apply them without restarting Vim.
Dynamically I want to edit/update hosts(etc/hosts) file to add domain. To edit hosts(etc/hosts) file
I have a text file that I want to edit by rewriting it to
I have a text file that I want to edit using Java. It has
I want to a edit a URL in a .cod file, I used XVI32
I want to edit links when the user changes the value of a <input
I want to be able to change a value in one place in my
I have some features content that I want to place after my shop content,
I want edit multiple strings at once by selection the list of strings needs
I want to edit the Velocity Report generated with Visual Studio 2010s scrum template.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.