awk -v pat="$pattern" 'NR == 1 {print $0}; $0 ~ pat {print $0}' infile.csv > outfile.csv
The first row of my file contains headers so I want them. Otherwise, I want only lines containing the BASH variable pattern which I am passing to awk with -v.
This is giving me all the lines containing the pattern but not the first line.
Mike
What operating system are you using?
Bash 4.1.10(4)
GNU Awk 4.0.2
CYGWIN_NT-6.1 1.7.17
Can you show us:
head infile.csv | cat -ev
Except for a little IP yes. csv file is unix type EOL
timestamp,sequence_number,alarm_id,alarm_class,resource,logged_by,reference,prev_state,log_action,final_state,alarm_message,generation_time,Comments,Duration,Name,alarm_code $
26-FEB-2013 08:44:08.000,xxxxxx,xxxxxx,EVENT,xxxxxx,xxxxxx,xxxxxx,G,R,R,xxxxxx,26-FEB-2013 08:43:04.000,,64,,NONE,xxxxxx$
Mike
---------- Post updated at 04:30 PM ---------- Previous update was at 04:20 PM ----------
Just to be clear the second rule is working. The first rule (NR == 1) is not.
Mike
I had a stupid error in a directory pointer in the surrounding script. Turns out the awk part was working just fine. I can't believe how much time I wasted on that error.
Mike