A simple Linux script to remove the program line number

Source: Internet
Author: User

When you browse a technical blog, you will findCodeThere is a row number, just like the following code:

1 void main ()
2 {
3 printf ("hello ");
4}

If this happens in the blog, you can also copy the row number without copying it (if the row is selected correctly), but other websites may not. To remove the line numbers when copying code, I wrote a script to remove these annoying lines. First, paste the code for you to see:

 
#! /Bin/bash
WhileRead line
Do
Num = 'echo"$ Line"| Awk'{Print $1}'`
Lennum =$ {# num}
Lenline =$ {# Line}
Echo"$ {Line: $ lennum: $ lenline-$ lennum}"
# Echo $ line
Done

Is it clear? Save the above Code to the denu. Sh file and add executable permissions to denu. Sh. The principle is to remove the first word in each line. The usage is as follows:
The hypothetical code.cpp.txt is the code with a line number copied from the Internet. You can use the following command to remove the line number:

 
Cat code.cpp.txt |./denu. Sh> code. cpp

The final code. cpp is the final file, but it may not be indented...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.