I have a data that looks like this:
-1033 - 222 100 -30 - 10
What I want to do is to capture all the numbers excluding ‘dash only’ entry.
Why my awk below failed?
awk '$4 != '-' {print $4}'
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your
awkscript saysHowever, you want to print it out if the line is not a dash
Default action is to print so no body is needed.
If you want to print group of numbers, you can use a GNU awk extension if you use gawk. It allows splitting records using regular expressions:
Now, instead of lines, it takes a group of numbers separated by a line containing only
-. Setting the field separator (FS) to a newline allows you to iterate over the numbers within such a group:However I agree with other answers. If you just want to filter out lines matching some text,
grepis the better tool for that.