Open vi with a command issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Open vi with a command issue
# 1  
Old 08-29-2012
Open vi with a command issue

Solaris 5.8, ksh

I need to open everyone's favorite editor, vi of course, with a command that will place me on a search string at the time of invocation:

Given this data file:
Code:
user1   pts/1        Aug 29 13:22 (10.12.214.101)
user2   pts/2        Aug 29 09:56 (10.12.212.132)
user3   pts/3        Aug 29 12:39 (10.12.212.132)
user4   pts/6        Aug 29 13:29 (10.12.212.117)
user5   pts/5        Aug 28 08:13 (10.12.212.132)
user6   pts/4        Aug 29 13:14 (10.12.212.96)

I want to open vi, with the cursor positioned on the first occurrence of "132" (last number in the second line).

Having a look at the man vipage in the invocation options section:
Code:
 +command | -c  command
           Begin editing by executing the specified  editor  com-
           mand (usually a search or positioning command).

I launch vi like this: $ vi +/132 filename.dat, expecting to end up positioned on the "1" of the first "132". Instead, I end up at the very first column of the row that contains the pattern. So, it seems that the "specified editor command" is not necessarily the same command as you would expect after vi has opened the file (where typing /132 indeed places me on the "132".

Putting double or single quotes around the "132" does not make a difference.

Any ideas? Is there a list of what commands are available when starting vi like this? I cannot seem to find a list.

Thank you,
Gary
# 2  
Old 08-29-2012
You can given any ex utility editing command to vi as the option argument to the -c option. Unfortunately, ex doesn't have a concept of a cursor position within a line, so you can't set the cursor to appear on the matched text unless it appears at the start of the line.
# 3  
Old 08-29-2012
Don't know if it's any help, and perhaps you already know, after opening you will get to the position you want if you type "n" for next.
# 4  
Old 08-29-2012
If you have vim and ksh/bash, you can use the -s option with process subsitution:

Code:
vi -s <(echo "/123") filename.dat

Edit: Oops Solaris 5.8 + ksh --- Ignore above.
# 5  
Old 08-30-2012
Just for the fun of it, is it possible to start vi in insert mode?

---------- Post updated at 09:59 AM ---------- Previous update was at 09:47 AM ----------

Quote:
Originally Posted by 244an
type "n" for next.
Yeah I figured that out. Too bad vi +/132n filename.dat does not work. Neither does vi +/132^Mn filename.dat. n for next is an ex command. Humph.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Open command

Hi , what does this below commands do in perl ? open(fd, ">>$received_notification_file"); print fd "$feed_name,,,$feed_expected_ind,$received_ind,$copied_ind,$market_pricing_dt\n"; close(fd); also this $tmp_file_Ctrl = "$Program.tempfileC_$feed_name" ; ... (1 Reply)
Discussion started by: ptappeta
1 Replies

2. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

3. Shell Programming and Scripting

PERL - issue with OPEN

Hi, I have a menu script written in PERL which calls some shell scripts and displays the return. I'm having a problem with OPEN. A section of the code is below: `./scriptlist.ksh 1`; open OUTPUT, "</home/$SCRIPTUSER/output"; { local $/ = undef; $_ =... (2 Replies)
Discussion started by: chris01010
2 Replies

4. Solaris

ulimit issue with open files descriptor

We have lots of error with "Too many open files" issue. So when I increase the limit to 36656 as suggested by this forum, and when i log out from the platform, it always went back to origin value, what has went wrong ? please any suggestion ? root@hsbc_milan> ulimit -a core file size ... (1 Reply)
Discussion started by: dehetoxic
1 Replies

5. UNIX for Dummies Questions & Answers

File processed in Unix had issue open using notepad

Dear all, I had a columned based file after processed from my script. In unix platform, my file is ok, with all columns sorted out nicely. But when i open in windows notepad, the columns are running out of order. Can some one help?? Thanks alot in advance (4 Replies)
Discussion started by: ymeyaw
4 Replies

6. Shell Programming and Scripting

How 2 run same command across all open terminals

Hi folks. This has been bothering me for a while. Among the 8 virtual desktops I'm using, I have 18 terminals open right now. I change some of my user configuration (e.g. put a new alias into ~/.bashrc); but in order to use this new added alias, I have to source the config file: .... (4 Replies)
Discussion started by: mirni
4 Replies

7. Shell Programming and Scripting

Open and System command in SFTP

Hi Unix team, Is there any alternative option and command which one can use in ftp for sftp usage. open, system command --> alternative for sftp usage -n option --> alternative for sftp usage sftp supports only binary transmission. how one can achieve ascii mode file... (8 Replies)
Discussion started by: mayleeshwaran
8 Replies

8. Shell Programming and Scripting

piping to 'open' command!

Hello! One command generates a file path, which I then want to open in finder. The slow way is this with C&P: $bundle show jquery-validator /Users/peter/.rvm/gems/ruby-1.9.2-p136/gems/jquery-validator-0.3.0 $open /Users/peter/.rvm/gems/ruby-1.9.2-p136/gems/jquery-validator-0.3.0 I... (4 Replies)
Discussion started by: pehrlich
4 Replies

9. UNIX for Dummies Questions & Answers

Issue: Compress in unix server and FTP to windows and open the compress file using Winzip

Hi All ! We have to compress a big data file in unix server and transfer it to windows and uncompress it using winzip in windows. I have used the utility ZIP like the below. zip -e <newfilename> df2_test_extract.dat but when I compress files greater than 4 gb using zip utility, it... (4 Replies)
Discussion started by: sakthifire
4 Replies

10. Solaris

open solaris FTP issue

Hi, I want to ftp from my virtual box to my desktop which is a windows machine. I have installed open solaris on my virtual box. though that is in network i am unable to ftp to my windows and vice versa. Please help (3 Replies)
Discussion started by: amult
3 Replies
Login or Register to Ask a Question