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

Selecting record based on a condition 1

Status
Not open for further replies.

mwesticle

Programmer
Nov 19, 2003
51
US
Hi... I have a file that contains name and address information. The primary address appears from byte 116-150. I need to pull all records off of that file where primary address is NOT blank, and put them into a new file. Can anyone help me out here???
 
Something like
Code:
awk 'substr($0,116,35) != "" { print }' file > newfile

--
 
Not tested, but try

awk 'substr($0,116,35) ~ /[^ ]*/' infile > outfile

CaKiwi
 
Well... I tried all the solutions... The two awk examples don't work for me because i need to pull off all records that have spaces in the primary address field. The shell example pulls off all records where primary address is blank, which is the opposite of what i need. Anyonw know how I could flip that around???
 
Sorry, misread your requirement:

#!/bin/ksh

while read record
do
x=$(echo "$record"|cut -c116-150)
case $x in
+([ ]))
continue;;
*)
echo "$record" >> newfile;;
esac
done < oldfile

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top