Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-28-2007, 02:18 AM   #1
LQ Newbie
Registered: Mar 2006
Posts: 22

Rep: Reputation: 15
Exclamation script for pasting fields in files

Following are the contents of file1

Following are the contents of file2


Now I want to replace the second field in file2 for john with the
second field for john present in file1.
So using cut command I have extracted the 2nd field from file2.
Following is the command used

grep "john" file1 | cut -d":" -f2 > pass

so now pass variuable contains second field of john from file1
i.e. pass contains "net".

So now how should I replace "ji" with "net" in file2?
Old 06-28-2007, 02:29 AM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
To read a particular field on a record in one file and alter it in another, you probably want to use awk.

This does seem like a homework problem, so I hope I'm not doing your work for you.

There is a book called "Gawk: Effective Awk Programming" that you may be able to install if you have a "gawk-doc" package, although sometimes it is supplied by the gawk package or the gawk source package. You didn't indicate your distro in Your user profile, so I can't be more specific. I have SuSE, and installed the gawk src.rpm file, and then used "rpmbuild -bp" to patch the source followed by "./configure && make pdf" to produce the pdf version of the book.
If you have Fedora Core, it is installed at /usr/share/doc/gawk-<version>/
Old 06-28-2007, 08:20 AM   #3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,814

Rep: Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553
Try sed tool, starting here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
script to relay the data in the fields to my email address generalachoo Programming 4 08-25-2006 08:54 AM
reading fields from files in python without \t \n dumpthecore Programming 1 12-11-2003 05:57 AM
cutting and pasting lxandrthegr8 Linux - General 8 08-17-2003 03:04 PM
Pasting webpage into spreadsheet flaw Linux - Newbie 3 09-22-2002 08:25 PM
GAIM - Pasting Sirrvs Linux - Software 2 09-08-2002 07:10 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:59 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration