my approach:
awk 'BEGIN{FS="|"}{if(length($
If there are lines without a 4th column and you want them too:
awk 'BEGIN{FS="|"}{if(NF<4||len
No need for grep.
Regards,
Oli
Main Topics
Browse All TopicsI have a Unix script that I need to parse a data file and kick out any line where the 4th field has less than 15 characters. I have this which works fine until there are no lines that need to be kicked out. When every line has a field 4 with at least 15 characters, the grep below yields a zero byte file. Any ideas?
awk -F"|", 'length($4)<15' /tmp/listfinal >> /tmp/deleteme
/usr/xpg4/bin/grep -v -f /tmp/deleteme /tmp/listfinal > /tmp/listclean
This question is in progress.
Our experts are working on an answer right now.
Sign up for immediate access to the solution once it becomes available.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: amit_gPosted on 2009-10-22 at 08:18:31ID: 25635220
Check the contents of /tmp/deleteme. If it has a newline (empty visually), it would cause the issue that you are reporting. This method that you are using is not reliable anyway. If a line is added to /tmp/deleteme, it may cause a valid line from /tmp/listfinal to be deleted if that line is a substring in any valid line. For example, take a case of just two field file and assume this is added as an invalid line in /tmp/deleteme
Hello|there
/usr/xpg4/bin/grep -v -f /tmp/deleteme /tmp/listfinal
would cause all of the following lines from /tmp/listfinal to be deleted even though they may be valid
Hello|there
Hello|thereIam
Hello|there Iam
If your files are small you can run awk twice.
awk -F"|" 'length($4)<15' /tmp/listfinal >> /tmp/deleteme
awk -F"|" 'length($4)>=15' /tmp/listfinal >> /tmp/listclean
If not, you can use the method given in one of your previous question. Something like it
awk -F, '$5 != "" {print > "/tmp/list.clean"} $5 == "" {print > "/tmp/deleteme"};' /tmp/list && mv /tmp/list.clean /tmp/list