[SOLVED] command to add a word at the beginning of each line that starts with a digit
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
command to add a word at the beginning of each line that starts with a digit
Hi,
I'm searching as it says in the subject for a "command to add a word at the beginning of each line that starts with a digit
eg:
1:23 This is the text..................................
Art1:23 This is how would like it to appear, the word would vary but I can fix that.
To do it by pasting would take ages.
Thanks in anticipation
lwv962
PS.I'm using bash.
Thanks for your reply Pan64.I've tried vim but it seems limited to substitution,I've used it several times.
The problem is entering 'a word ' ONLY on lines that start with a digit/s eg.
1:12 Here is text
no text here
nothing here either
1:13 text again with digits
non digit line
I've tried :1,6 s/^/Gen/ in vim and got:
Gen1:12 Here is text
Genno text here
Gennothing here either
Gen
Gen1:13 text again with digits
Gennon digit line
[SOLVED] command to add a word at the beginning of each line that starts with a digit
danielbmartin, many many thanks for your excellent and most
helpful response,it solved my problem 100%.
I have tried the awk but I'll get to the sed tomorrow.
The awk solution may be boiled down into fewer keystrokes if that sort of thing appeals to you. The ternary operator is difficult to read until you get used to it. The general form is:
Code:
if-this-is-true?then-do-this:else-do-this;
Note the ? : ; punctuation.
With this InFile ...
Code:
Now is the time
1:13 for all 26 good men
to come 4:40 to
2:02 the aid of their party.
That's all, folks!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.