Using with vim substitute command: lines created are not scanned in future steps. Can they be?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I know regex well, for vim and a few other programs. But for sed, it is sometimes strange to use. I never try it, unless it is something ready to run, or with changes i understand how to do. Can you show something to me?
sed is basically the same:
Code:
sed -E 's/.{72}\S{,8}/&\n/g' your_file
With indentation and guarding against short lines that would be
Yep. 72 characters is the soft limit. Or what the fmt man page calls goal. The splitting occurs after each 72 characters plus 0 to 8 non-spacing characters. So 80 characters is the hard limit. The {,8} quantifier is greedy, so it will try to consume as many characters as it can (up to 8). As soon as there's a white space among those 8 characters, the RE fires and splitting occurs. If there's no white space in that range, the splitting occurs after the 80th character anyway.
I am still not sure i understand it. Does this splitting happens only from 73 to 80 spaces, or before 81 if there was no space in this interval?
Does this splitting happens only from 73 to 80 spaces, or before 81 if there was no space in this interval?
The splitting happens before the first white space after the 72th character, or before the 81th character if there was no white space in that interval.
The splitting happens before the first white space after the 72th character, or before the 81th character if there was no white space in that interval.
If i understand you right, this is not my idea.
Considering your limits, but my wish: it should be in the *last* space after 72th, but before 80th; or before the 81th character.
With my limits: the *last* space before 80th character; or before the 81th character (which means no space was found until it).
Exactly what i was thinking about writing, after seeing your command and explanation. Simpler than most things we have seen here. But i kind of worried if it would work, since any of you wrote that regex (in vim or not).
There is a problem with this: it will split lines shorter than N, if these lines have a space:
With indentation and guarding against short lines that would be
Code:
sed -E '/.{81,}/s/.{72}\S{,8}/&\n\t/g' your_file
shruggy, i think there are strange things in this regex you wrote. See:
Code:
/.{81,}/s/.{72}\S{,8}/&\n\t/g
^ ^ ^ ^ ^
1 2 3 4 5
My questions:
a. Should 2 be a slash or a backslash?
b. Assuming that 2 is a backslash, why this regex has 3 parts, with 4 slashes separating them, instead of just 2? (this is something i have never seen before, so i did not even bother to search about it)
If there are these mistakes in your messages, i suggest that you edit them. The commands may not solve my problem, but others may find them useful.
1234567890 2345
67890 234567890
# there is a tab inserted here!
The result is indented, but the indentation make the new line go beyound the demanded limit of 14 chars (in my example). And there is an extra tab, in the end of the file.
People, can you, please, write a sentence or a short paragraph to describe the workings of a regex or some command you send? This can be valuable, i think, and it is not hard.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.