-1

I have one file

FILE 1:

Edward-201-singer
Andrew-James-404-writer

I want output as

Edward
Andrew-James

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
1

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

1

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

Edward
Andrew-James

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

Edward--singer
Andrew-James--writer

... which is not what you want.

0

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

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

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