The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
How to read the content of the particular file from tar.Z without extracting? kalpeer Shell Programming and Scripting 12 01-08-2009 09:07 AM
find for specific content in file in the directory and list only file names madhu_Jagarapu AIX 2 12-23-2008 02:13 AM
read from a file to a list pinkgladiator Shell Programming and Scripting 4 11-18-2008 01:23 PM
read list of filenames from text file and remove these files in multiple directories fxvisions Shell Programming and Scripting 5 08-07-2008 03:59 PM
read list of filenames from text file, archive, and remove fxvisions Shell Programming and Scripting 5 03-20-2007 09:56 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-09-2009
tanit tanit is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 6
Need help with awk - how to read a content of a file from every file from file list

Hi Experts.

I need to list the file and the filename comes from the file ListOfFile.txt.
Basicly I have a filename "ListOfFile.txt" and it contain
Example of ListOfFile.txt
/home/Dave/Program/Tran1.P
/home/Dave/Program/Tran2.P
/home/Dave/Program/Tran3.P
/home/Dave/Program/Tran4.P
/home/Dave/Program/Tran5.P

Each file contain the same format on the first 2 lines about it's version.
I need to read the data from thesecond line column 3
Example of Tran1.P
/****************************
01122008 /home/Dave/Program/Tran1.P 10.05
****************************/
After I get the data from second line column 3 (10.05), I need to compare this data to the same filename that I found from file mapVersion.txt
Example of mapVersion.txt
Tran001.P|3.4
Tran020.P|4.2
Tran1.P|10.05
Tran12.P|4.11
Tran2.P|3.0
Tran3.P|10.5
Tran3A.P|12.3
Tran4.P|4.1
Tran5.P|1.2

I want to know if it's the same or not.

I know how to write script with ksh but I like to use awk to do this because I think it's faster than while loop.

Thanks in advance,
Tanit
  #2 (permalink)  
Old 03-09-2009
tanit tanit is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 6
Anyone can help with this? or do you know the command that may lead to pull data from a file which in a file?
  #3 (permalink)  
Old 03-09-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Please don't 'bump-up' posts - it's against the rules.
  #4 (permalink)  
Old 03-09-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Quote:
Originally Posted by tanit View Post
Hi Experts.

I need to list the file and the filename comes from the file ListOfFile.txt.
Basicly I have a filename "ListOfFile.txt" and it contain
Example of ListOfFile.txt
/home/Dave/Program/Tran1.P
/home/Dave/Program/Tran2.P
/home/Dave/Program/Tran3.P
/home/Dave/Program/Tran4.P
/home/Dave/Program/Tran5.P

Each file contain the same format on the first 2 lines about it's version.
I need to read the data from thesecond line column 3
Example of Tran1.P
/****************************
01122008 /home/Dave/Program/Tran1.P 10.05
****************************/
After I get the data from second line column 3 (10.05), I need to compare this data to the same filename that I found from file mapVersion.txt
Example of mapVersion.txt
Tran001.P|3.4
Tran020.P|4.2
Tran1.P|10.05
Tran12.P|4.11
Tran2.P|3.0
Tran3.P|10.5
Tran3A.P|12.3
Tran4.P|4.1
Tran5.P|1.2

I want to know if it's the same or not.
The same as what?

Quote:
Originally Posted by tanit
I know how to write script with ksh but I like to use awk to do this because I think it's faster than while loop.
Why?
Quote:
Thanks in advance,
Tanit

Last edited by vgersh99; 03-09-2009 at 10:56 AM.. Reason: remove code - misread the question - see radoulov's code
  #5 (permalink)  
Old 03-09-2009
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Yes, we must ask you to be patient.

Try this (use nawk or /usr/xpg4/bin/awk on Solaris):

Code:
awk -F\| 'FILENAME == ARGV[1] { 
  m[$1] = $2; next
  }
FILENAME == ARGV[2] { 
  n = split($0, t, "/"); f[$0] = t[n]
  ARGV[ARGC++] = $0; next
  }
{ 
  FNR == 1 && FS = "[ \t]*"  
  if (FNR == 2) 
  print FILENAME ": version", ($NF == m[f[FILENAME]] ? \
  "OK" : "mismatch " $NF " <-> " m[f[FILENAME]])
  }' mapVersion.txt ListOfFile.txt
  #6 (permalink)  
Old 03-09-2009
tanit tanit is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 6
Thank you very much Radoulov.

I am looking into the code now =)
  #7 (permalink)  
Old 03-09-2009
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Notice that if the input files are large and you have GNU awk, including nextfile after the print statement in the if block (you should add another pair of braces too) will significantly improve the performance of the script.
Sponsored Links
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 06:56 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