Operating System - HP-UX
1748211 Members
4924 Online
108759 Solutions
New Discussion

Re: script to match character

 
Intothenewworld
Advisor

Re: script to match character

thx replies,

I am sorry that when I apply it to my real case , it still have problem , as in my real case , the master file has a bit difference Dennis Handly 's method is delimited by space only ( f1 f2 f3 is delimited by space ) , the real file is a bit complicate.

The below is the master file of the real case , in the string (eg. aaa bbb ccc ddd eee) , there are other space before this string .

#vi master.txt
"ffd" hg " gg""""""  aaa bbb ccc ddd eee " " "
"fd "jg "" """""  xxx yyy zzz mmm ooo " " "
"hdgd"jg"""fd""f""  ggg hhh iii jjj kkk " " "


I want to compare ( in my master file ) is

1) after 9 " , then
2) the 4th column of the string that delimited by space ,

can advise what can i do ?

thx

Intothenewworld
Advisor

Re: script to match character

I may be make it confued so I would like to clearly re-post my question .

 

I have a master file , the content is as below.
#vi master.txt
"d"""""""" aaa bbb ccc ddd eee " " "
"""y""d"""" xxx yyy zzz mmm ooo " " "
""f""""""" ggg hhh iii jjj kkk " " "

I also have some text files ,
eg.
#vi file1.txt
aaa
#vi file2.txt
bbb
#vi file3.txt
ccc
#vi file4.txt
ddd

I would like to check if the fourth column ( eg. ddd mmm jjj ) is exist in these text files , if not exist , then output this line , in this case , output the below ( as ddd exists in file4.txt )
"""y""d"""" xxx yyy zzz mmm ooo " " "
""f""""""" ggg hhh iii jjj kkk " " "

The requirement is check
1) after 9 " , and
2) the 4th column of the string that delimited by space .

can advise what can I do ? Thanks

Dennis Handly
Acclaimed Contributor

Re: script to match character

>1) after 9 ", then
>2) the 4th column of the string that delimited by space

 

Ok, try this:

while read line; do
   IFS_save=$IFS
   IFS='"\n'    # split on double quote
   echo "$line" | read f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11
   IFS=$IFS_save
   f10=${f10# *}  # strip leading spaces
   f10=${f10% *}  # strip trailing spaces
   echo "$f10" | read f1 f2 f3 f4 f5  # split on spaces
   fgrep -q "$f4" file*.txt
   if [ $? -ne 0 ]; then
      echo "$line" # print original line if field not found
   fi
done < master.txt