Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need help with grep command line filtering

Posted on 2013-06-25
4
Medium Priority
?
346 Views
Last Modified: 2013-06-25
I have the following code to loop through lines of the file and read only the lines with characters a-z

grep "^[a-zA-Z]" $FILE1 | while read LINE
do
     

done

I also need to ensure that the code above ignores the very first line and any lines starting with dashes "-". How can accomplish that?

I know I can exclude dashes by using grep -v "^-" but how do I combine it with the existing condition and incorporate the exclusion of the first line
0
Comment
Question by:YZlat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
nemws1 earned 800 total points
ID: 39275236
Just keep piping them.  The tail command will actually skip the first line, as you requested.

tail -n +2 $FILE1 | grep "^[a-zA-Z]" | grep -v "^-" | while read LINE
do

done

Open in new window

0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 200 total points
ID: 39275279
You're already filtering for lines starting with [a-zA-Z]. Such lines cannot start with a dash.

But anyway, how about awk?

awk 'NR>1 && /^[a-zA-Z]/ && !/^-/' $FILE1 | while read line ...
0
 
LVL 35

Author Comment

by:YZlat
ID: 39275537
good point woolmilkporc!:)
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39275745
Good enough for 50 points and an assist, as it seems.

Thx.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question