1st solution: WE can give number of time we need to print spaces with printf. 2nd solution: With a variable by which we can add how many number of space we want to add at last of the string.
Thanks,
R. Singh
Last edited by RavinderSingh13; 01-24-2015 at 03:05 PM..
I want to add X ($VARIABLE) number of spaces (which comes from RANDOM)
i.e.
VARIABLE='14'
then it will do:
In short: this is not possible. The reason is that regular expressions have certain limitations and this is one of them.
If you are interested in a general and very scientific explanation of why this is so: regular expressions are of the same expressive power as regular languages, which themselves are Type-3 languages in the Chomsky-Schützenberger hierarchy. (Look up "Chomsky hierarchy" and "regular language" in Wikipedia or the net for more detail.) An expression of the form <expression> times variable would need a so-called backreference, which is not possible in a regular language because it would not be context-free any more. See the Pumping Lemma, which can be used to prove this.
Having said this: you already got some workarounds of one or the other form. Just be aware that everything you can achieve is more or less clever workarounds for the mentioned limitation.
Sed replace using same pattern repeating multiple times in a line
I have text like below in a file:
I am trying to replace the above line to following
How can I acheive this?
I am able to do it if the occurrence is for 1 time:
But If I try like below
I am getting like this:
I have to... (4 Replies)
Hi,
I am trying to get lines between the last occurrences of two patterns. I have files that have several occurrences of “Standard” and “Visual”. I will like to get the lines between “Standard” and “Visual” but I only want to retain only the last one e.g.
Standard
Some words
Some words
Some... (4 Replies)
Problem: I have a lot of files, the files first line should always have 4 spaces before any text. Occasionally some of the files will miss the leading spaces and it's a problem. This is only in the first line.
So if there are 4 spaces then text, do nothing. If there are not 4 spaces, add 4... (2 Replies)
Not sure about the title if someone has a better name for it please lemme know and I will edit the title.
I have several (10+ files) which look something like:
File 1:
12/28/2009 04:0 8
12/28/2009 04:4 4
12/28/2009 05:0 4
.
.
.
File 2:
12/28/2009 04:1 7
12/28/2009 04:2 3... (2 Replies)
Im trying to add 5 blank spaces to the end of each line in a file in a sed script. I can figure out who o put the spaces pretty much anywhere else but at the end.
thanks
Karl (7 Replies)
Hey,
Im trying to format the last command to tell me just the user names, logins, and the time that they were logged in. So far I got the users logins using a loop that counts the amount of times a user logged in but im not sure how to start the time array. The time im trying to use is the last... (2 Replies)
I'm trying to make a bash shell script that will allow a user to modify another file based on input they give. Maybe someone can see what I'm doing wrong here. I'm still pretty new at this...
Let's say my temp file contains this:
0 1 HELLO 3 4
And here's the code:
old=(0 1 3 4)
new=(zero... (2 Replies)