I have one file



I want output as


closed as unclear what you're asking by Stéphane Chazelas, Jeff Schaller, roaima, αғsнιη, Kiwy May 7 '18 at 12:27

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.

  • 1
    Dash isn’t a letter...? – Jeff Schaller May 7 '18 at 9:46
  • So, you want all characters in a line, until you find a digit. And then exclude a - prior to that digit as well? – cunninghamp3 May 7 '18 at 9:47
  • Please clarify your question. Your example doesn't match your requirements. – Stéphane Chazelas May 7 '18 at 9:52
  • @StephaneChazelas : Its like i want to print every thing in a given line until i find -[0-9] (any number) – acroniks May 7 '18 at 9:55
  • 3
    Please edit your question to add that information. – Stéphane Chazelas May 7 '18 at 9:59

Assuming you want all characters in a line, until you find a digit. And then exclude an optional - prior to that digit as well:

sed 's/-\{0,1\}[[:digit:]].*//' your-file

(with GNU sed, you can replace \{0,1\} with \?. Or sed -E 's/-?[[:digit:]].*//' with some).

This should handle your examples, although without more detail I can't say it would handle everything in your file.

If you want to change your file in-place, with some sed implementations, you can add a -i.bak to the sed command (backs up file to your-file.bak, makes changes to your-file) or add a > new-file on the end to write new-file with the results


To remove everything from after the first digit preceded by a dash (and the dash-digit as well):

sed 's/-[0-9].*//' file

With the data given in the question in the file file, this generates


Removing digits only (as asked in the title of the question) can be done with tr -d '0-9' <file, but would produce


... which is not what you want.


Without knowing anything else about the format, this works for the two values you've provided:

while read
    echo "${REPLY%-*-*}"
done < file1

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