blackmamba
blackmamba

Reputation: 1992

Cut command with delimiter Control-A

I am trying to get some columns from file1 to file2 using cut command with delimiter Control A.

This is what I tried:

cut -d^A -f2-8 a.dat > b.dat

If my records are like this:

A^AB^AC^AD^AE^AF^AG^AH^A$

my command gives:

AB^AC^AD^AE^AF^AG^AH

Is my command wrong or am I putting the delimiter in a wrong way?

So it leaves Control-A's A in the starting point.

Upvotes: 2

Views: 11592

Answers (2)

konsolebox
konsolebox

Reputation: 75488

^A is character number 1 in the ASCII table a.k.a Start of Heading character. If you're using bash, you can have this:

cut -f 2-8 -d $'\x01'

Or use printf (can be builtin or an external binary):

CTRL_A=$(printf '\x01')
cut -f 2-8 -d "$CTRL_A"

You can also verify your output with hexdump:

hexdump -C b.dat

Upvotes: 16

Mark Setchell
Mark Setchell

Reputation: 207465

I can't really understand your question, but would suggest you use tr to change your Control-As into something else more workable and maybe then change them back when you are finished:

tr '^A' ',' < yourfile | do some cutting using commas | tr ',' '^A' > newfile 

Upvotes: 0

Related Questions