I've two documents that are the result of SQL Queries.

For exemple i've my Doc1.lst that is :

    John1    0
    Julien  10
    Jules3   0
    Julie   30

On this Doc1.lst, I used sed to have only the name part, so Doc2.lst is :


I don't master enough the sed command to catch only the numbers, so I would like to know if there is a way to create a Doc3.lst that take the Doc1.lst and delete into it the content of Doc2.lst

It would be a sort of reversed catenate. By the way, if you have the sed command to catch only the numbers that would be great.

closed as unclear what you're asking by cuonglm, jasonwryan, Michael Homer, Anthon, don_crissti Mar 11 '15 at 11:14

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.

  • 2
    why not awk if you need just numbers from Doc1.lst: awk '{ print $2 }' Doc1.lst ? – taliezin Mar 11 '15 at 8:19
  • cat Doc1.lst |awk '{print $2}' > Doc3.lst – Milind Dumbare Mar 11 '15 at 8:19
  • @Miline Possible it should be $3 – Costas Mar 11 '15 at 8:23
  • 1
    @Costas your solution takes the numbers from names.. has same problem as the answer. – Milind Dumbare Mar 11 '15 at 8:29
  • 1
    @Miline See edited – Costas Mar 11 '15 at 8:31

To get the output you want, you could either use awk, cut or sed. The former is preferable.

If your file Doc1.lst is as follow

John1    0
Julien  10
Jules3   0
Julie   30

The following awk command will get the output you want. Assuming field separator is a space.

awk '{print $1}' Doc1.lst

Using cut

cut -d' ' -f1 Doc1.lst

Or using sed. Note. sed is a stream editor and you don't want to use sed for this task. But here is the line you want anyway.

sed 's/\([a-zA-Z]*\).*/\1/' Doc1.lst


awk '{print $1}' Doc1.lst > Doc3.lst

  • 1
    This is a typical useless use of cat If I understand the question, the OP want's the first field only. That'd be awk '{print $1}' Doc1.lst There is no need for cat. awk can read a file as well. – Valentin Bajrami Mar 11 '15 at 8:40
  • In my case your command work but not using {print $2} but {print $1}. Your answer gives me the names, using $1 it gives me the numbers. – Julien S Mar 11 '15 at 8:42
  • @val0x00ff Updated – Milind Dumbare Mar 11 '15 at 9:03
  • @Miline You now just need to substitute $2 with $1 and off you go! – Valentin Bajrami Mar 11 '15 at 9:04
tr -s '[:space:]' \\n <infile | grep '^[0-9]'


sed '/^[0-9]/P;y| |\n|;D' <infile

...or probably just...

sed 's/.* //' <infile

...though for the last one you might want to do s/ *$// first in case there are trailing blanks.

More generally you can number a group with sed...

sed 's/ *[^ ]\{1,\} *//' <infile

...written like that would strip from a line the first group of not-space characters and all surrounding spaces - which would leave you w/ the numbers. However...

sed 's/ *[^ ]\{1,\} *//2' <infile

...would instead do the same to the second not-space group per line - which would leave you with just the names.

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