![]() |
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 |
| checking ERRors in files | ali560045 | Shell Programming and Scripting | 4 | 06-19-2008 10:56 AM |
| how to login into another ip and checking for the files | saikumar_n | Shell Programming and Scripting | 2 | 07-11-2007 02:34 PM |
| how to login into another ip and checking for the files | saikumar_n | UNIX for Advanced & Expert Users | 1 | 07-11-2007 10:13 AM |
| checking for files on ftp... | jithinravi | UNIX for Dummies Questions & Answers | 3 | 06-22-2007 11:25 AM |
| Searching list of entries in file for actual files in dir | not4google | UNIX for Dummies Questions & Answers | 2 | 10-18-2006 11:24 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
checking entries between files
I need to write a script for:
I have two files where I need to check entries and sort of compare: file1: data01 data02 data03 data04 data05 . . . data81 file2: /vol/vx/data01 /vol/vx/data02 /vol/vx/data03 /vol/vx/data04 /vol/vx/data05 . . So each entry from file1 should have corresponding entry in file2. If entry exists it should pass but if there is no entry it should say: error: entry dataXXX has no entry in file2. Appreciate your help. |
|
||||
|
awk
input:
Code:
a: data01 data02 data03 data04 data05 b: /vol/vx/data01 /vol/vx/data02 /vol/vx/data05 Code:
No entry for:data03 No entry for:data04 Code:
nawk 'BEGIN{FS="/"}
{
if (NR==FNR)
test[NR]=$4
else
{
flag=0
for (i in test)
{
if ($1==test[i])
flag=1
}
if (flag==0)
print "No entry for:"$1
}
}' b a
|
|
|||||
|
Hi.
It's useful to see different approaches. I like the awk solutions. The shell loop solution is also good, but will call grep for each line, possibly a drawback for long files. Here is a solution using *nix commands, although a modern shell is required for the process substitution, "<( ... )". This may be useful if it is not appropriate or possible to use awk, perl, etc.: Code:
#!/usr/bin/env bash # @(#) s1 Demonstrate feature. set -o nounset echo debug=":" debug="echo" ## Use local command version for the commands in this demonstration. echo "(Versions displayed with local utility \"version\")" version >/dev/null 2>&1 && version bash sort cut comm sed echo echo " Input file data1:" cat data1 echo echo " Input file data2:" cat data2 echo echo " Results:" comm -23 <( sort data1 ) <( cut -d/ -f4 data2 | sort ) | sed -e 's/^/ No entry for: /' exit 0 Code:
% ./s1 (Versions displayed with local utility "version") GNU bash 2.05b.0 sort (coreutils) 5.2.1 cut (coreutils) 5.2.1 comm (coreutils) 5.2.1 GNU sed version 4.1.2 Input file data1: data01 data02 data03 data04 data05 Input file data2: /vol/vx/data01 /vol/vx/data02 /vol/vx/data05 Results: No entry for: data03 No entry for: data04 |
|
||||
|
Excellent help guys ... it works !! Thanks to all who provided help.
|
| Sponsored Links | ||
|
|