python - AWK doesn't work on first row delimited by ^A -


i have file looks similar this(^a non printing character , below view in vi), columns delimited ^a , rows terminated \n.

# input 2013-10-07 10:40:14.170976^awww.abc.com/0 2013-10-07 10:40:14.171074^awww.abc.com/1 2013-10-07 10:40:14.171101^awww.abc.com/2 2013-10-07 10:40:14.171133^awww.abc.com/3 2013-10-07 10:40:14.171156^awww.abc.com/4 ... 

you can recreate file using python script below:

# test.py datetime import datetime in range(10):     print chr(1).join(str(elem) elem in [datetime.now(), 'www.abc.com/' + str(i)]) 

then

python test.py > input 

i tried first column(timestamp) of file using awk.

cat input | awk 'fs="\x01"{print $1}'  2013-10-07 2013-10-07 10:40:14.171074 2013-10-07 10:40:14.171101 2013-10-07 10:40:14.171133 2013-10-07 10:40:14.171156 ... 

somehow, first row skipped part after timestamp, 1 knows did wrong. thank you!

it's because variables have set before beginning process input files, in begin block, like:

awk 'begin { fs="\x01" } {print $1}' input 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -