• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1329
  • Last Modified:

file too large to open for Vi editing

SCO Unix system. :-

Hi, I need to edit some dates in a transaction file but the file is quite big and won't open as temp table.

I know the specific dates I want to change and don't need be selective so a find/replace funtion would be all I need.

Can this be done with vi at command line without having to open the file in its entirety ?

My knowledge of vi is basic (I can get around!) and I do not know Awk or Sed.

Many thanks
Kylie


0
Kyliem
Asked:
Kyliem
  • 6
  • 4
1 Solution
 
ahoffmannCommented:
awk, sed or perl would be the better solution, probably
Tell us which pattern should be replaced by which text, and we can suggest a solution

If you're adicted to use vi, you may either try
  vi -R hugefile
which opens in read-only mode and does not use a tmp-file, you can save changes there with
  :w!

or you can use split to size down your file, see
  man split
0
 
KyliemAuthor Commented:
hi, thanks, I simply want to replace a date (in format dd/mm/yyyy) eg  26/02/2006 with date of 27/02/2006   I know there are about 25 lines in total to be changed out of what is a large file.

I thought about sed command 'g/{olddate}/s/{olddate}/{newdate}/g/p'   and was going to put it in a 1 line script and call it using command line:  
sed -f -n {scriptfile} {myfile} > {newfile}

{} not included in command line obviously and I expect I would need use backslash to negate the command line '/' in my date format yes.

I will also try the read-only mode, cheers very much

Kylie
0
 
KyliemAuthor Commented:
I would have typed the command I thought about using in full but my keyboard refuses to return the backslash character, I get hash # instead.  Not very helpful for scripting !  but luckily I won't be using the pc to do it on.

Kylie
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ahoffmannCommented:
> .. my keyboard refuses to return the backslash character,
your keybord returns characters?
LOL
I guess you mean something else ;-)
check with
 stty -a

sed -e 's#26/02/2006#27/02/2006#g' <oldfile>newfile
# or
perl -i.bak -pe 's#26/02/2006#27/02/2006#g' file
0
 
KyliemAuthor Commented:
Hi, now you have confused me.  Did you mean to use the char$ '#' when typing your commands out?  do they represent spaces or slashes ?

Does it not need the date to be specified as 26\/02\/2006 so that the '/' doesn't get interpreted as a command to follow?

Thanks
K
0
 
KyliemAuthor Commented:
The -R read only mode still returns a Temp file too large error and I cannot access the lines I want for editing purposes.  

If I did use 'split' what command would I use to re-join them all ?

Thanks
K
0
 
KyliemAuthor Commented:
Ignore the query regards # and spaces.  nothing like getting round to testing it.  I'm ok now, can carry on and try editing the file.
0
 
ahoffmannCommented:
> The -R read only mode still returns a Temp file too large ..
strange ...
try using view instead vi -R
or you can use another place for temp file (/var/tmp by default). This is a bit tricky 'cause vi uses ex and both do not use the TMP environment variable. You either must open vi without a file and then do:
  :set directory=/path/to/huge/space
  :r your-huge-file
or you have to use ex's EXINIT environment variable before, something like:
  EXINIT="set directory=/path/to/huge/space"

> If I did use 'split' what command would I use to re-join them all ?
cat fileaaa fileaab fileaac > file

> Ignore the query regards # and spaces.
what do you mean here?
0
 
KyliemAuthor Commented:
Hi, your sed command:   sed -e 's#26/02/2006#27/02/2006#g' <oldfile>newfile
  worked ok so am accepting this answer in respect to question asked.  However, since the date change effected, caused a duplicate record error, (valid error due to transactions found on subsequent days) I will have to edit the file and will need use a large temp file area so many thanks for the extra info on using vi and EXINIT.  I expect to use this info and have upped the pts value respectively.  

many thanks
Kylie
0
 
ahoffmannCommented:
glad to have helped, somehow ..
Good Luck.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now