LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   stuck with list and VI (https://www.linuxquestions.org/questions/linux-newbie-8/stuck-with-list-and-vi-697701/)

biblers 01-16-2009 09:15 AM

stuck with list and VI
 
Hi guys and girls,

I am new here, this is my first post.

I am stuck with something,

I have a list like this

arontal
balilee
clebe
dradual
guimpe
hagioscope
qanap
aassock
dearsecloth
pegumene

What I need to do is change the first character to look like this

[Aa] if the word starts with an "a" (without brackets), so if it starts with a b it would need to be [Bb]

What I have done so far is in VI

I copy all words with an "a"

Then I do

:%s/a/[Aa]/ (good start)
:%s/$/,/g (get commas at the end)
then I go to the top and keep pressing J (get it all on one line)

Then I copy all the "b" words and do it again.

I am sure I can do this with an "for i in" but I have NO idea how, how can I just do it all in one time, a ~ z

Sorry for bargin in!

Didier Spaier 01-16-2009 09:25 AM

Looks like home work. For now I give you a clue : in the American Standard Code for Information Interchange, look at decimal or hex values for 'A' then 'a', 'B' then 'b', etc.

biblers 01-16-2009 09:44 AM

Didier,

I am sorry, but that went in/out (as in, I dont get it).. I am pretty thick with it all.. a total starter,

But I think I found A=1 0 1 0 , along those lines you mean?

I guess I would have to do something along the lines of

for i in "1st character"

change "1st character" to "["Capital 1st character""lowercase 1st character]"

Now I KNOW that if I type the above somewhere, NOTHING will happen, other then a very confused server,

Didier Spaier 01-16-2009 09:59 AM

If not already done have a look here.

In other words: try to find an algorithm to find the decimal code for letter 'a' knowing the decimal code for letter 'A', and so on.

It shouldn't be that difficult ...

Or may be I didn't understand well your question. In that case feel free to post the text of the exercise as it was given to you ;)

biblers 01-16-2009 10:04 AM

No no, it is not homework

I am running a script to filter on keywords, but to add the keywords I need to place them as follows.

[Aa]redence, [Kk]redo, [Cc]rosier, [Cc]ruet, [Cc]urate, [Cc]uria, [Cc]ustos,

I have a long list of words like this

unalist
cnaneled
snction
vndercroft
qnhouseled
gerger
fernicle
zersicle

And need to make it look as the above, I have figured it out doing it only for all "a" words, as such

:%s/a/[Aa]/ (good start)
:%s/$/,/g (get commas at the end)
then I go to the top and keep pressing J (get it all on one line)

but I wish I could do it for all words in one time.

BCarey 01-16-2009 10:37 AM

Here's a 2-pass version:

%s/^\(\a\)/[\u\1\l\1]/
%s/\n/,/

Brian

biblers 01-16-2009 10:43 AM

HOLY CRAP

How did that work? (woohooo)

Asy 01-16-2009 11:06 AM

Quote:

Originally Posted by BCarey (Post 3411003)
%s/^\(\a\)/[\u\1\l\1]/
%s/\n/,/

Nice code Brian!

Explanation:
first line:
Code:

%s = search hole file
/  = start of the search string
^  = only the stuff on the begin of the line ( $ = for end of line stuff)
\( \) = get in the a buffer
\a = get only aphanumeric characters
/  = end of the search start op the substitution
[  = [
\u = put next char to uppercase
\1 = get the buffer (make it uppercase because of previous line)
\  = escape the meaning of the next character
|  = |
\1 = get the buffer again
]  = ]
/  = end of the substitution

second line:
Code:

\n = newline changed by only a comma (,)

BCarey 01-16-2009 11:15 AM

Asy,

That's actually "\l" not "\|".

Brian

biblers 01-16-2009 11:46 AM

your a scholar and a gentleman,

Sincerely THANK YOU!

biblers 01-18-2009 03:20 AM

Sorry ... Now I got the problem that the lines can only be 255 characters.

And I am going to have to put all these keywords in a command line, like this;

IndexIf [Aa]redence [Kk]redo [Cc]rosier [Cc]ruet [Cc]urate [Cc]uria [Cc]ustos

But is seems to be limited to 255 characters per command line, where the total now is around 38.000 characters.. in the one IndexIf command line

Once more, can I ask?

biblers 01-18-2009 05:27 AM

I guess i can simply do

:250yl and then ctr a enter esc p
But I would have to do that a few thousand times..

Any tips?

biblers 01-18-2009 06:33 AM

DId it.. my god what a job

This is what I did.

I copied the long list of 38000 keywords into a file
then

fmt file > file2

then

:%s/^/command /g

And voila!

Woohoooooooooooo

shynijinil 01-21-2009 12:14 AM

telnet
 
when I execute the command 'telnet 127.0.0.1' I got the message as 'unable to connect to remote host. Connection refused.' What will be the problem? Can you give any clarification?

chrism01 01-21-2009 12:29 AM

@ shynijinil: Please don't hijack this thread. Start a new one for your qn.
Also, check your firewall, is telnet server running (shouldn't be).
Also add your distro to your profile so we know what you've got.


All times are GMT -5. The time now is 07:03 PM.