LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

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


Hi,
Following are the contents of file1
john:net:tim
ika:fi:do


Following are the contents of file2

john:ji:tim
dfs:hi:la


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, 01:29 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
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>/gawk.ps
 
Old 06-28-2007, 07:20 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,406

Rep: Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396
Try sed tool, starting here: http://www.gentoo.org/doc/en/articles/l-sed1.xml
 
  


Reply


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 07:54 AM
reading fields from files in python without \t \n dumpthecore Programming 1 12-11-2003 04:57 AM
cutting and pasting lxandrthegr8 Linux - General 8 08-17-2003 02:04 PM
Pasting webpage into spreadsheet flaw Linux - Newbie 3 09-22-2002 07:25 PM
GAIM - Pasting Sirrvs Linux - Software 2 09-08-2002 06:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:43 AM.

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