?
Solved

Need help with grep command line filtering

Posted on 2013-06-25
4
Medium Priority
?
345 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

801 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