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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF statement to compare if the value has double quotes "" or not 4

Status
Not open for further replies.

wellster34

Programmer
Sep 4, 2001
113
CA
Hi,

I'm learning unix as I go along but I'm having a problem. I have a data file that contains the following:

"123","45"
..etc...

I want to check in the "45" position to see if the 45 is missing so it only leaves double quotes -> ""

If the file contains:
"123",""

I want to omit that record of information from the data file. So, I tried the logic below:

awk '{
if( substr($0,7,2) -eq '""' ) print $0
}' < input.dat > new.dat

It obviously does not work. Does anybody know how to fix this code or have a new idea?

Thanks for your time.
 
\&quot;\&quot;

alternative, test the string length (no I don't know awk, so I can't tell you how)
 
Wellster:

This works on my Solaris 7 box. Change the Field Separater to , and check for each field = &quot;&quot;; skip each line with a &quot;&quot;. Probably somebody can come up with something faster:

awk ' BEGIN { FS=&quot;,&quot; }
{
for (i=1; i<=NF; i++)
{
if($i == &quot;\&quot;\&quot;&quot;)
next
}
print $1
} ' input.dat


Regards,

Ed
 
nawk 'BEGIN {FS=&quot;,&quot;}
!match($0,&quot;\&quot;\&quot;&quot;)
' input.dat vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Awesome! Thanks for all your help. I got it to work. The main piece that worked was the &quot;\&quot;\&quot;&quot;. I do not understand what that does but it works!!! Thanks again!
 
The \ character is known in UNIX programming as the escape character. In all UNIX scripting languages you can use the escape character to tell the program that you are looking for that item instead of using that item.

Example:

if I wanted to echo the line &quot;John says &quot;How do you do?&quot;&quot;, I would have to escape the quotes inside the stuff I want to print out to the screen.

This is how it would be accomplished:

echo &quot;John says \&quot;How do you do?\&quot;&quot;

If you try it without the \ before the quotes you want to escape, it will not work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top