1

I am working on a .txt file which is the output of a neuroscience program called fsl. It does have 2 column and I want to remove the second one, I test some of the suggested codes but it seems like the Linux commands couldn't separate the two columns. Any idea how to discard the second column? For example, I tried cut -f1,1 num.txt but it doesn't work.

0 0.000000 

49 1435.537231 

11 322.263489 

0 0.000000 

0 0.000000

0 0.000000

0 0.000000 

360 10546.804688 

83 2431.624512

0 0.000000 

2 Answers 2

4

awk is a powerfull tool IMO worth learning the basics at least. There are many tutorials. To unconditionally print the first column, all you need is:

awk '{print $1}' input.txt

The advantage over cut is that it will consider any blank character as the separator (though with some implementations, it's limited to the SPC and TAB characters only), will ignore leading and trailing ones and consider sequences of one ore more blanks as one separator.

1
  • To @StephaneChazelas: Your edits are better than my brief answer originally was. Thank you for kindly enhancing it.
    – VPfB
    Jun 1, 2017 at 8:57
3

This looks like a space-delimited file.

To extract the first column to a new file:

$ cut -d ' ' -f 1 data >data.new

The -d ' ' tells cut to use a space as the delimiter. The default is to use a tab character.

1
  • 1
    Thanks for your prompt response, I really appreciate it. Jun 1, 2017 at 6:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .