Thursday, June 30, 2011

Using grep to extract specific FIX protocol tags values from a file

grep -o -w '\(48\|55\)=[^[:cntrl:]]\+' FILE | perl -pe 's/(\d+=[^\n]+)\n/\1~/' | perl -pe 's/([^~]+~[^~]+)~/\1\n/g'

grep -o -w '\(48\|55\)=[^[:cntrl:]]\+' FILE | tr '\n' '~' | perl -pe 's/([^~]+~[^~]+)~/\1\n/g'

grep -o -w '\(48\|55\)=[^[:cntrl:]]\+' FILE | sed 'N;s/\n/ /'

-o Print only the matched parts of a matching line
-w Select lines containing matches that form whole words (a whole char is a letter, digit and underscore)

No comments: