Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
I want to select the word only if starts with 'LN'. So I used awk '/LN/ {print $1}' but this returns other words too with 'LN' anywhere except the first two char like 'NY00xxLN' which I don't want. How to tell it to match only first 2 char in the word??
Name: James Boothe Date: August 21, 2007 at 09:03:08 Pacific
Reply:
Here is a basic loop to look at each word in the line. I don't think you are interested in locating multiple qualifying words on the same line, so upon encountering the first qualifying word, I break out of the for-loop.
I used the "like" operator and beginning-of-expression anchoring, but you could also use if (substr($w,1,2)=="LN")
awk '{ for (w=1;w<=NF;w++) if ($w~"^LN") {print "whatever ..." break} }' infile
0
Response Number 2
Name: dips Date: August 21, 2007 at 23:52:00 Pacific
Reply:
Thanks... That didn't work. I tried with nawk also but it says Syntax error....But i tried this $nawk -F"," '$2~/^LN/{print $2}' infile.txt It works... I only want "the searching" to be done in the 2nd field of the file
Summary: Hello, I try to detect the presence of a char in a string. This is korn shell. mystring="1234-" mychar="-" if [ mystring includes mychar ] ; then exist=1 else exist=0 fi What should I write inst...
Summary: Hi, I'm trying to use AWK to find a line in a file equal to 2 different variables and write it to another variable. I can find the values individually but I can't work out how to put them together. ...
Summary: Hi, I am having a problem determinig how to write an awk script that will do the following. I have a file and in that file I am looking at a certain field. This field will contain one of tow things. A...