Solved

Need help with grep command line filtering

Posted on 2013-06-25
4
343 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 200 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 50 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machineā€¦
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 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.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

739 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