How can I get multiple info from different files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I get multiple info from different files
# 1  
Old 02-07-2007
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  
Old 02-07-2007
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  
Old 02-07-2007
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  
Old 02-07-2007
And just for completness with sed:

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep strings on multiple files and output to multiple files

Hi All, I want to use egrep on multiple files and the results should be output to multiple files. I am using the below code in my shell script(working in Ksh shell). However with this code I am not attaining the desired results. #!/bin/ksh ( a="/path/file1" b="path/file2" for file in... (4 Replies)
Discussion started by: am24
4 Replies

2. Shell Programming and Scripting

Run one script on multiple files and print out multiple files.

How can I Run one script on multiple files and print out multiple files. FOR EXAMPLE i want to run script.pl on 100 files named 1.txt ....100.txt under same directory and print out corresponding file 1.gff ....100.gff.THANKS (4 Replies)
Discussion started by: grace_shen
4 Replies

3. UNIX for Dummies Questions & Answers

Run one script on multiple files and print out multiple files.

How can I run the following command on multiple files and print out the corresponding multiple files. perl script.pl genome.gff 1.txt > 1.gff However, there are multiples files of 1.txt, from 1----100.txt Thank you so much. No duplicate posting! Continue here. (0 Replies)
Discussion started by: grace_shen
0 Replies

4. Shell Programming and Scripting

Script to execute command to get info from multiple servers

Hi, I want to collect info from a no. of servers whether there grub.conf contain "elevator" parameter or not. What I want is sudo cat /etc/grub.conf | grep -q "elevator=noop"; echo $? If output is "0", I want name of that host in a file called "present" if its not "0", I want that... (4 Replies)
Discussion started by: stunn3r
4 Replies

5. Red Hat

Info on /dev/dm files

Hi, I was looking at my /dev directory and found some files of the pattern dm?. I searched on google and found that it is a device manager file for LVM. But nothing but that. Can someone give me some info on when these files are created and if we can use this as instead of... (7 Replies)
Discussion started by: prithvirao17
7 Replies

6. Shell Programming and Scripting

awk, multiple files input and multiple files output

Hi! I'm new in awk and I need some help. I have a folder with a lot of files and I need that awk do something in each file and print a new file with the output. The input file name should be modified when I print the outpu files. Thanks in advance for help! :-) ciao (5 Replies)
Discussion started by: gabrysfe
5 Replies

7. UNIX for Dummies Questions & Answers

Using AWK: Extract data from multiple files and output to multiple new files

Hi, I'd like to process multiple files. For example: file1.txt file2.txt file3.txt Each file contains several lines of data. I want to extract a piece of data and output it to a new file. file1.txt ----> newfile1.txt file2.txt ----> newfile2.txt file3.txt ----> newfile3.txt Here is... (3 Replies)
Discussion started by: Liverpaul09
3 Replies

8. Shell Programming and Scripting

merging info from 2 files into 1

Hi, I have 2 files that I need to combine. I'm not sure if there is an easy way to use grep or something to combine them how i need. Basically I have 2 csv files. Each file shares an ID for a line of information, but has a bunch of other so I can't easily combine them. file1:... (2 Replies)
Discussion started by: kevin9
2 Replies

9. AIX

need to extract info from log files

hi guys i need to extract information from log files generated by an application. log file has the following lines for each process.. ---------------------------------------------- Fri Aug 03 12:06:43 WST 2007 INFO: Running project PROJECT1 Fri Aug 03 12:06:43 WST 2007 INFO: Source Files... (7 Replies)
Discussion started by: kirantalla
7 Replies

10. Shell Programming and Scripting

rewrite the same info in 3 different files

i would like to be able rewrite the same info in 3 different files /path/file1.ext /path/file2.ext /path/file3.ext can u help me please with shell script ? lets say i want to write "12345" thanks (6 Replies)
Discussion started by: strok
6 Replies
Login or Register to Ask a Question