Home  |  Forums  |  914 Info  |  Blogs
 
914World.com - The fastest growing online 914 community!
 
Porsche, and the Porsche crest are registered trademarks of Dr. Ing. h.c. F. Porsche AG. This site is not affiliated with Porsche in any way.
Its only purpose is to provide an online forum for car enthusiasts. All other trademarks are property of their respective owners.
 

Welcome Guest ( Log In | Register )

> OT: Calling unix experts, Need "vi" assistance
Rusty
post Aug 9 2004, 09:18 AM
Post #1


914 Guru
*****

Group: Admin
Posts: 7,973
Joined: 24-December 02
From: North Alabama
Member No.: 6
Region Association: South East States



Sorry for the OT post.

I have a text file that I need to edit.

I need to edit every record on that file (record positions 34-37) to change whatever is in those positions (only) to a four digit number. What is currently in those positions varies dramatically.

My only text editor I have on the system is vi.

Anyone got a command I can use?

thanks,
Lawrence
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
 
Reply to this topicStart new topic
Replies
bperry
post Aug 10 2004, 12:35 PM
Post #2


Lurker
**

Group: Members
Posts: 477
Joined: 16-February 04
From: Dallas, Tx
Member No.: 1,661



Man its been a while but I love vi and regular expressions.
We used to have contests like this at work back in the 80's
to see who could do it in the shortest (most obtuse) way.

Its been years since I've done any of this
but you could try something like this from the command line.

:1,$s/^\(..... place 32 dots here\)....\(.*\)/\1####\2/

This should modify the entire file.

There should be EXACTLY as many periods/dots between the
first set of parens as you want to skip over.
Then EXACTLY as many periods/dots between the first
set of parens and second parens as you want to replace.
Replace #### with the new numbers/text you want.
(doesnt have to be the same length as what is being replaced)
This works by matching the begining characters and puting them in a substring
then matching the replacement characters and finally puting the tail
end of the string in another stubstring. Then it puts the first
substring back, then the new text, followed by the second substring.

Hopefully, I remembered correctly and the WEB tools didn't mangle
any of the special characters.


(NOTE: I did download a vi versions for windows and this does work.)
Regular expressions are cool! and very consistent across unix.

For all of you wondering how come I got so deep into such
techno dweeb stuff, its because back in the "old days" when you
were on a 300 baud modem, you wanted as little screen activity
as possible and the ":" commands of vi are exactly the same as
the "ed" commands which is where vi came from.

--- bill
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Posts in this topic
Lawrence   OT: Calling unix experts   Aug 9 2004, 09:18 AM
fiid   hey, It sounds like you need to make this edit on...   Aug 9 2004, 09:46 AM
thomasotten   upload the text into a database like mysql, if you...   Aug 9 2004, 10:04 AM
sgomes   Wow! Two things: 1) vi is still getting disc...   Aug 9 2004, 10:05 AM
mikester   If the records were all the same it would be easy ...   Aug 9 2004, 10:07 AM
vortrex   are you using real vi, as in on a unix station of ...   Aug 9 2004, 10:09 AM
Lawrence   Here's a sample record: 000104659 W91XLM4094...   Aug 9 2004, 10:17 AM
Root_Werks   :idea: Oh man, it has been a while. But even So...   Aug 9 2004, 10:39 AM
Lawrence   The BA0 only varies a bit. I could run several sw...   Aug 9 2004, 10:48 AM
thomasotten   Ok, how about writting a shell script that reads e...   Aug 9 2004, 10:54 AM
kafermeister   Ok, Don't laugh. The last time I ran into som...   Aug 9 2004, 11:00 AM
Lawrence   Thomas, The rest of the data is different in ever...   Aug 9 2004, 11:01 AM
thomasotten   yeah, it is just looking for the same position. I...   Aug 9 2004, 11:04 AM
mikester   The simplest way to do this is in vi. If it's...   Aug 9 2004, 11:18 AM
tat2dphreak   ok, if this is on a windows machine that you are t...   Aug 9 2004, 11:56 AM
fiid  
  Aug 9 2004, 02:23 PM
fiid   We should start a 914 Wiki is what we should do.   Aug 9 2004, 04:24 PM
Gint   Get this figured out yet? Here's a very simpl...   Aug 9 2004, 05:15 PM
Lawrence   Thanks guys! It's morning here now... I...   Aug 9 2004, 09:44 PM
Gint   Here's an even shorter version: sed -e 's...   Aug 9 2004, 10:05 PM
Root_Werks   Me thinks Gint wins the prize for this one! ...   Aug 10 2004, 11:53 AM
bperry   Man its been a while but I love vi and regular exp...   Aug 10 2004, 12:35 PM


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

- Lo-Fi Version Time is now: 7th July 2025 - 12:45 AM