Solved

Need help with grep command line filtering

Posted on 2013-06-25
4
342 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
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

713 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