0

Frequently we need to copy-paste a code snippet and compile-run it. The problem is that the lines of code are tagged by line number. So what utility to use to elegantly discard the line numbers?

6
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by Skifter
0

Frequently we need to copy-paste a code snippet and compile-run it. The problem is that the lines of code are tagged by line number. So what utility to use to elegantly discard the line numbers?

Your question is ambiguous at best. I might have to make some assumptions
If you are using an Unix/Linux base
If your copied data looks like:

Line one
Line two
    Space, line 3
Etc...

If you had it copied as it is to a file.
Then you can use sed, vim, or gvim, to make a substitution by using a regexp pattern.

sed 's/^[0-9]*\.//g' < copied_file > cleaned_file

or in vim/gvim

:% s/^[0-9]*\.//g
:w
0

Or you could try Gawk/Awk

awk '{for (i = 2; i <= NF; ++i){printf("%s ",$i);{if (i==NF){printf("\n");}}}}' filename
0

cut is my personal favorite for trimming one column, like a line number repeatedly. simple syntax, fast to type.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.