0

How can I extract the third value and all subsequent ones (i.e., discard the first two values) from each line in a text file containing, for example, the following values?

1 1112 0 1 2
2 1111 0 2
3 1211 1 0 3

I want to ignore 1 1112, 2 1111, and 3 1211 and get only the values

0 1 2
0 2
1 0 3

all of which belong to what I call the third group of values for every line.

closed as unclear what you're asking by Jeff Schaller, Stephen Rauch, user34720, Rui F Ribeiro, mdpc Jun 27 '17 at 0:53

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Is it always skipping the first two number groups? What have you tried so far? – John Jun 26 '17 at 19:54
  • 3
    What's the formula? echo 0 1 2 could be an Answer at this point. – Jeff Schaller Jun 26 '17 at 20:01
  • Sorry let me elaborate. As @John said i am skipping two number groups and fetching the third group of numbers. It is not just this one line it could be multiple lines. – Sab Jun 26 '17 at 20:04
2

Looks like a simple table format, what I can sugest is to use cut command and remove the first two columns delimited by space.

$ echo "01 1112 0 1 2" | cut -d " " -f 3- 

Using this with a file:

$ cut -d " " -f 3- file.txt > output_expected.txt

Give a try

0

Just for fun, a regex approach:

$ sed -r 's/^(.[^ ]* ){2}//g' <<<$'1 1112 0 1 2\n2 1111 0 2\n3 1211 1 0 3'
0 1 2
0 2
1 0 3

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