find a string and copy the string after that

Hi! just want to seek help on this:

i have a file wherein i want to find a string and copy the string after that and paste that other string to a new file.
ex:
TOTAL 123456
find "TOTAL" and copy "123456"
and paste "123456" to a new file

NOTE: there are many "TOTAL" strings on that file.

anyone pls help me! thanks!

provide some more sample input., you say there will be more than one TOTAL, so on what basis, you want to find?

Have you tried anything?

For example:
2345
4567
8910
TOTAL 1234
......
3456
7890
1234
TOTAL 5678
.....

In a file, there are many lines with "TOTAL" on it. I want to find "TOTAL" on that file and copy the next string after that on that certain line. Afterwards, paste that other string a new file.
Actualy, i haven't tried anythng yet. I don't know where to start. Tnx!

---------- Post updated at 01:14 PM ---------- Previous update was at 01:12 PM ----------

And there is no fixed interval on the occurence of the "TOTAL"s lines. Thanks!

You mean to say TOTAL 1234 should go in new file
and likewise TOTAL 5678 also should go in the same new file.

or only 1234 and 5678....in any case first read
man grep, and man cut

Only 1234 and 5678, in a new file with this format:
1234
5678
...

Can i have a sample command for this? Thank u very much!

Try it for 5 mins...with grep and cut
look for grep -w option
and cut -f and -d options.

I know grep can find "TOTAL" but i don't know how to copy the next string.

use below command:

grep "TOTAL" input_file | awk '{print $2}' > output_file

regards,
Ashish

I'll give it a try! Thank you so much!

Please read the man pages of cut and grep.

grep -w "TOTAL"  file.txt | cut -d" " -f2

use command :

grep TOTAL input_file | awk '{print $2}' > output_file

and it paste the cut string to a new file? Tnx

grep Total <Filename> | awk '{print $2}' > Output