-1

I have a file with 900.000 columns, the structure is:

1613 1200000012000500000011111.......
112345 1200000012000500000011111.......
1287659 1200000012000500000011111.......
1234 1200000012000500000011111....... 
712826  1200000012000500000011111.......

I need only the numbers before the space, this is a new file as:

1613 
112345 
1287659 
1234 
712826 

I try with

cat -df.txt |cut -d |,| -f7

but it does not work.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Johanna Ramirez
  • 161
  • 1
  • 9
  • 1
    You could simply do `awk '{print $1}' Input_file` and let me know if this helps you?Considering that you need to print digits before first space in all lines here. – RavinderSingh13 Aug 08 '20 at 10:04
  • 1
    This might help: [bash: shortest way to get n-th column of output](https://stackoverflow.com/q/7315587/3776858) – Cyrus Aug 08 '20 at 10:23
  • you are attempting with cut, using a strange syntax for the delimiter, but also asking for the 7th field... – Daemon Painter Aug 08 '20 at 10:43
  • The `cut` command you tried is really weird; why would you try to use `|` as f it were a quote character, and whay do you say `-f7` if you don't want the seventh field? – tripleee Aug 08 '20 at 11:01
  • 900,000 columns or rows? – Julio Aug 08 '20 at 11:05

1 Answers1

1

A couple of approaches, based on your attempts:

awk

As also suggested by RavinderSingh13, straightforward approach is

awk '{print $1}' yourfile.txt

remember awk doesn't need cat.

cut

With vanilla cut as well, this should work:

cut -f1 -d' ' yourfile.txt

Here you require cut to print the first field -f1 where the delimiter is a whitespace -d' '. Remember also cut doesn't need cat (unlike me always forgetting).

Other very nice approaches with grep and sed can be found in this question

Daemon Painter
  • 3,208
  • 3
  • 29
  • 44