Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple command script ?

Status
Not open for further replies.

mark7

Technical User
Apr 22, 2002
2
SK
I wonder if anybody can help with this simple task. I need to make it work in AIX version of Unix.
I'd like to read from file 1, from let's say position 20-36 and search for the string in file 2. If the string doesn't exist, write the output to a file.

So the script would work something like this. I enter the names of the file 1 and file 2.The script will take the string from position e.g.20 to 36 line by line and then looks for the string in the file 2. If it finds the match it will write output let's say in file 3, if it doesn't - it'll write the unmatched strings in file 4.

Is it possible to write a simple command script that will work like that ?

Thanks in advance for you soon reply.

p.s. any other solutions, recommendations and ideas are welcome !

Mark


 
Hi,

in the input file - do you have spaces/tabs inside the lines ,or it's plain strings ? "Long live king Moshiach !"
 
I have spaces resp. tabs, it's like :

[line 1]080404 4444899978 000000037 etc.
[line 2]080505 9999990000 090909099 etc.
[line x]...... .......... ......... etc.
what will be the differece then ?

 
Try:
(file1 is a source file,file2 is a file you grep,matchfile and nomatchfile are output files)

#!/bin/ksh
rm matchfile nomatchfile >/dev/null 2>&1
head -36 file1|tail -16 >TEMP
integer NLINES=`cat TEMP|wc -l`
while [[ $NLINES != 0 ]];do
STRING=`cat -n TEMP|grep "^\ \ \ \ \ $NLINES"|cut -c 8-200`
grep "$STRING" file2 >/dev/null
if [[ $? = 0 ]] ;then
echo "$STRING" >> matchfile
else
echo "$STRING" >>nomatchfile
fi
NLINES=$NLINES-1
done
"Long live king Moshiach !"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top