Hi, I am fairly new at using Unix / awks / shell.
I have created a file (using awk) which contains a list of application numbers of failed apps. From this list I want to know which file they originated from. To do this I must scan through dozens of other files which contain these application numbers to discover where they came from. This is where I am stuck!
Can somebody please help!
Dan - please provide more information. OS and version - application(s) - file output from awk script - some info on the application numbers. Why you are "stuck" in searching through these files. There just isn't much info in what you posted so far to have anyone give you a clear answer.
Take a look at the man pages for find and egrep for possible help in your 'search'.
>> OS and version - application(s)
I think its Tinyterm (?)
Sorry, but I thought it would all be about the same.
>> file output from awk script - some info on the application >> numbers.
They contain letters and numbers, 20 characters long
>>Why you are "stuck" in searching through these files.
Because I dont know how to do it!
As I said, I'm new to using awks.
The file I created consists of hundreds of application numbers.
Using this file, I need to check, one line at a time, which file it has come from. There are dozens of these files to look through. Each application number is within one of these files.
Hope this is now enough information.
Thanks for your help
for appNum in `cat appNames.txt`
do
grep -l $appNum * 2>/dev/null
done
where appNames.txt contains list of appNames created by yr awk script;
In the above scripts * can be replaced by the some pattern
for dozens of files u are going to scan ;
Hi, I'm using Unix on tinyterm. I have used an awk to produce a file containing dozens of application numbers (which contain max 20 chars). These numbers are on each line. What I need to do is check where each of these app numbers have come from. By this I mean which MACS file. There are hundreds of these MACS files which can be broken down using tar xvf to produce applic.txt - this is a pipe delimited file which contains numerous application numbers and details of the app. The application numbers do not have any patterns to them, ie they look like: D/54645-54 or 42548786, etc. I am stuck. I do whether or not to search the MACS pipe delimited file or first tar xvf it then search the pipe delimited applic.txt file. I also am having trouble getting the right code to do this. I think using a while may be best, "while not last line" or something similar (?). Please help me!
Firstly, TinyTERM is just a terminal emulator, usually run under Windows.
To find your OS version, try "uname -a". To get your Shell "echo $SHELL" or "echo $0" at the prompt.
Anyway. We really need to see a sample of this file.
You can process files line-by-line with a while loop
# just prints out each line
while read line; do
echo $line
# put other processing here.
done < my_file_name
If your file is pipe delimited, and you want to say pull the fifth field out with awk, a simple one liner such as
awk 'BEGIN{ FS="|" } {print $5}' my_file_name
This will work as long as your "application number" is in the same field, consistently.
When you say where the application numbers "have come from" what do you mean?
How have you used "awk" to create the file?
We need a lot more information, and most importantly
1) A sample of the file
2) What you want to get out of the file (i.e. what output are you expecting?)
Cheers
ZB
Threads merged - please don't post the same questions twice (read the rules). Keeping one thread on your problem will assist others in helping you - so they don't have to ask the same questions again and again. Please go back through the thread and answer the questions that were asked.
OS version - SCO-SV
sco unix
Shell - /bin/sh
>When you say where the application numbers "have come from" >what do you mean?
What I mean is which MACS file are they from (MACS files contain many application numbers), each application number comes from only one MACS file. I need to "match them up".
Eg MACS0147 contains app number 24488.
24488 would be in my app numbers file, which looks like:
D2156/59
4234234
3454366
etc
So the output I want would be:
434363 MACS4324234
78458953 MACS5734985
etc
ie the app number followed by the MACS file it was found in.
#!/bin/sh
while read line; do
grep "$line" /path/to/my_macs_files/*
done < my_apps_list
exit 0
This will present output of the form
macs_file_1:12039123
macs_file_2:jk23nf
You can always sort that to your liking, or pipe through something like
awk 'BEGIN {FS=":"} {print $2, " ", $1}'
or whatever you want.
If you get duplicates, and the only thing inside the macs file is the app number, change the grep line to be
grep "^${line}$" ......
Cheers
ZB
I'll try that now.
Thanks for your help
This is my code:
file="hunt.err"
cat $file | awk '{ line1=$0
swl=substr(line1,17,10)
app=substr(line1,29,20)
if(swl=="App. No. :") {
print app
}
}' > failed_apps
while read line; do
grep "$line" /home/danielr/awks/test/macs/*
done < failed_apps
Unfortunately it doesn't seem to work.
It takes a few minutes to run, when it finishes nothing happens.
Any idea whats wrong?
Post a few sample lines of your failed_apps file.
It must contain ONLY the app number (which must appear exactly within a macs file) on each line.
Cheers
ZB
Here goes:
10/50590658-04
D/36819791-07
10/50652080-06
etc
I copied EXACTLY a couple of these app numbers into my macs file, but it didnt work.
But if I grep them from command line it does (?).