I am storing output of pig file in a directory Which contains lines with multiple columns separated by delimiter \\u0001.

Now in shell script I want to fetch 7th column field from the output.

I tried below commands however didn’t get required output:

cnt=`awk -F '^A' '{print $7,$1}' $f`
cnt=`cut -d'\\u0001' -f8 $f | awk '{s+=$0}END{print s+0}'`

How to achieve the same?

Here is sample file:

printf "c1\\u0001c2\\u0001c3\\u0001c4\\u0001c5\\u0001c6\\u0001c7\\u0001c8" > 001.txt

Try the following syntax:

awk -F '\001' '{print $7}' < myfile


  • -F - use the next arg as field separator,
  • '\001' - method of expressing a byte with a value of 1,
  • '{print $7}' - for every line of input, output the 7th field followed by a newline,
  • < myfile - use myfile as input.
  • Can you expand your answer to explain what this code does and how it addresses the problem? Unexplained code is discouraged, because it doesn't teach the solution (and RTFM isn't a substitute). Your answers will attract more upvotes with some explanation. Thanks. – fixer1234 Mar 4 '16 at 19:58
  • This answer should have been explained. – MariusMatutiae Mar 5 '16 at 11:34
  • awk - the program – Bing Bang Mar 10 '16 at 17:03

You can use cut command for that, e.g.

cut -d $'\001' -f7 001.txt

Where -d is your delimiter and -f is your column number.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.