![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
|
|||||
|
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
|
|
|||||
|
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 | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|