The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
Adding Multiple Lines to Multiple Files dayinthelife Shell Programming and Scripting 2 06-04-2008 12:50 PM
need to extract info from log files kirantalla AIX 7 08-16-2007 12:33 AM
How to find all the log files under the root directory -- Need Info gkrishnag UNIX for Advanced & Expert Users 2 09-06-2006 04:38 AM
Searching multiple files with multiple expressions Anahka Shell Programming and Scripting 6 01-07-2004 06:24 PM
rewrite the same info in 3 different files strok Shell Programming and Scripting 6 03-29-2003 01:50 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-07-2007
efernandes efernandes is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 5
How can I get multiple info from different files

HI,

Supose I have these 2 files:

file1.txt
Name: John
Age:28
DateOfBirth:21/12/2004

file2.txt
Name: Thomas
Age:30
DateOfBirth:11/1/2003

I need to retrieve into a single file the "Name" and "DateOfBirth" from the 2 files, so the result looks like this:

file3.txt
John:21/12/2004
Thomas:11/1/2003

Regards
Elio
  #2 (permalink)  
Old 02-07-2007
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,915
With bash/ksh93:


Code:
while read;do 
	case "$REPLY" in 
		Name*)printf "${REPLY#*: }:";; 
		Date*)printf "${REPLY#*:}\n";;
	esac
done< <(cat file1 file2)>file3

For ksh < ksh93 use
cat file1 file2 | while read ...

Last edited by radoulov; 02-07-2007 at 04:14 PM..
  #3 (permalink)  
Old 02-07-2007
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,915
With awk:

GNU Awk

Code:
awk '{print $3,$7}' RS= FS="[ :\n]" OFS=":" file1 file2

nawk

Code:
nawk '{print $3,$7}' RS= FS="[\\\\n: ]" OFS=":" file1 file2

  #4 (permalink)  
Old 02-07-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,242
And just for completness with sed:


Code:
sed -n 's/^[ND][^:]*:[ ]*\([^ ].*\)/\1/p' file1.txt file2.txt > file3.txt

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0