LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-16-2009, 09:15 AM   #1
biblers
LQ Newbie
 
Registered: Jan 2009
Posts: 8

Rep: Reputation: 0
Question 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!
 
Old 01-16-2009, 09:25 AM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,058

Rep: Reputation: Disabled
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.
 
Old 01-16-2009, 09:44 AM   #3
biblers
LQ Newbie
 
Registered: Jan 2009
Posts: 8

Original Poster
Rep: Reputation: 0
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,

Last edited by biblers; 01-16-2009 at 09:46 AM.
 
Old 01-16-2009, 09:59 AM   #4
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,058

Rep: Reputation: Disabled
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
 
Old 01-16-2009, 10:04 AM   #5
biblers
LQ Newbie
 
Registered: Jan 2009
Posts: 8

Original Poster
Rep: Reputation: 0
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.
 
Old 01-16-2009, 10:37 AM   #6
BCarey
Senior Member
 
Registered: Oct 2005
Location: New Mexico
Distribution: Slackware
Posts: 1,639

Rep: Reputation: Disabled
Here's a 2-pass version:

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

Brian
 
Old 01-16-2009, 10:43 AM   #7
biblers
LQ Newbie
 
Registered: Jan 2009
Posts: 8

Original Poster
Rep: Reputation: 0
HOLY CRAP

How did that work? (woohooo)
 
Old 01-16-2009, 11:06 AM   #8
Asy
LQ Newbie
 
Registered: May 2008
Location: The Netherlands
Distribution: Ubuntu
Posts: 25

Rep: Reputation: 16
Quote:
Originally Posted by BCarey View Post
%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 (,)
 
Old 01-16-2009, 11:15 AM   #9
BCarey
Senior Member
 
Registered: Oct 2005
Location: New Mexico
Distribution: Slackware
Posts: 1,639

Rep: Reputation: Disabled
Asy,

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

Brian
 
Old 01-16-2009, 11:46 AM   #10
biblers
LQ Newbie
 
Registered: Jan 2009
Posts: 8

Original Poster
Rep: Reputation: 0
your a scholar and a gentleman,

Sincerely THANK YOU!
 
Old 01-18-2009, 03:20 AM   #11
biblers
LQ Newbie
 
Registered: Jan 2009
Posts: 8

Original Poster
Rep: Reputation: 0
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?
 
Old 01-18-2009, 05:27 AM   #12
biblers
LQ Newbie
 
Registered: Jan 2009
Posts: 8

Original Poster
Rep: Reputation: 0
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?
 
Old 01-18-2009, 06:33 AM   #13
biblers
LQ Newbie
 
Registered: Jan 2009
Posts: 8

Original Poster
Rep: Reputation: 0
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
 
Old 01-21-2009, 12:14 AM   #14
shynijinil
LQ Newbie
 
Registered: Jan 2009
Posts: 1

Rep: Reputation: 0
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?
 
Old 01-21-2009, 12:29 AM   #15
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
@ 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.
 
  


Reply

Tags
list, vi



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to list all files recursively, in a non-broken list? nyle Linux - Newbie 1 12-16-2008 10:52 PM
sorting a list into comma separated list nixlearn Linux - Newbie 22 12-03-2008 06:21 AM
adding proc list and task list of active processes. pravin.embedded Linux - Newbie 1 09-02-2008 01:20 PM
Is there a list on the web similar to the Hardware Compatibilty List for Windows ? andhrooy Linux - Newbie 2 08-10-2008 09:06 AM
Problems with items stuck in Mandriva 2007 install/Update list in MCC Clived Mandriva 2 02-15-2008 03:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration