Need help with awk - how to read a content of a file from every file from file list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with awk - how to read a content of a file from every file from file list
# 1  
Old 03-09-2009
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  
Old 03-09-2009
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  
Old 03-09-2009
Please don't 'bump-up' posts - it's against the rules.
# 4  
Old 03-09-2009
Quote:
Originally Posted by tanit
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 12:56 PM.. Reason: remove code - misread the question - see radoulov's code
# 5  
Old 03-09-2009
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  
Old 03-09-2009
Thank you very much Radoulov.

I am looking into the code now =)
# 7  
Old 03-09-2009
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use while loop to read file and use ${file} for both filename input into awk and as string to print

I have files named with different prefixes. From each I want to extract the first line containing a specific string, and then print that line along with the prefix. I've tried to do this with a while loop, but instead of printing the prefix I print the first line of the file twice. Files:... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

2. Shell Programming and Scripting

Read and concatenate content file and file name

Hi all, i need a bash script. I have a 3 file named Milano, Torino, Firenze Into file i have: Milano Marco Luca Giorgio Michele PatrizioTorino Marco Giulio Emilio MicheleFirenze Luca Giorgio Marco Saverio EmilioThe output should be a all_city.csv file like: (3 Replies)
Discussion started by: kamose
3 Replies

3. Shell Programming and Scripting

How to remove exisiting file content from a file and have to append new file content?

hi all, i had the below script x=`cat input.txt |wc -1` awk 'NR>1 && NR<'$x' ' input.txt > output.txt by using above script i am able to remove the head and tail part from the input file and able to append the output to the output.txt but if i run it for second time the output is... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

4. Shell Programming and Scripting

cut the variable from the line and use it to find the file and read the content of that file

Hi, I am working on one script..I am having files in the below format file 1 (each line is separated with : delimeter) SPLASH:SPLASH:SVN CIB/MCH:MCH:SVN Now I want from file 1 that most left part of the first line will store in... (6 Replies)
Discussion started by: rohit22hamirpur
6 Replies

5. Shell Programming and Scripting

How to read file and only output certain content

Hi - I have a file containing data like :- cn=tommy,cn=users,c=uk passwordexpirydate=20100530130623z cn=jane,cn=users,c=uk passwordexpirydate=20100423140734z cn=michael,cn=users,c=uk passwordexpirydate=20100331020044z I want to end up with a file that looks like:-... (6 Replies)
Discussion started by: sniper57
6 Replies

6. Shell Programming and Scripting

read file content

i have one file abhi.txt its contents are home8/mc09ats/UnixCw/backup/file1 home8/mc09ats/file2 i want to read this content of file using while loop.. in this i want to seperate the content as follows path=home8/mc09ats/UnixCw/backup file=file1 echo path echo file can you... (1 Reply)
Discussion started by: AbhijitIT
1 Replies

7. Shell Programming and Scripting

Read a file content with awk and sed

Hello , I have huge file with below content. I need to read the numeric values with in the paranthesis after = sign. Please help me with awk and sed script for it. 11.10.2009 04:02:47 Customer login not found: identifier=(0748502889) prefix=(TEL) serviceCode=(). 11.10.2009 04:03:12... (13 Replies)
Discussion started by: rmv
13 Replies

8. Shell Programming and Scripting

read a file and use the content for mapping

help me pls.. :( i want to read a mapping file. Below is the content of my mapping file. 6221,189,SMSC1,OMC1,WAP1 6223,188,SMSC2,OMC2,WAP2 so when my program running msisdn="622130302310" while not EOF if substring($msisdn,1,4) == "6221" -- > "6221" read from the file then echo... (0 Replies)
Discussion started by: voidmain
0 Replies

9. Shell Programming and Scripting

Read a file and search a value in another file create third file using AWK

Hi, I have two files with the format shown below. I need to read first field(value before comma) from file 1 and search for a record in file 2 that has the same value in the field "KEY=" and write the complete record of file 2 with corresponding field 2 of the first file in to result file. ... (11 Replies)
Discussion started by: King Kalyan
11 Replies

10. AIX

find for specific content in file in the directory and list only file names

Hi, I am trying to find the content of file using grep and find command and list only the file names but i am getting entire file list of files in the directory find . -exec grep "test" {} \; -ls Can anyone of you correct this (2 Replies)
Discussion started by: madhu_Jagarapu
2 Replies
Login or Register to Ask a Question