Solved

Need help with grep command line filtering

Posted on 2013-06-25
4
337 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
Comment Utility
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
Comment Utility
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
Comment Utility
good point woolmilkporc!:)
0
 
LVL 68

Expert Comment

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

Thx.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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 previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now