Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Urgent vi/sed help pls

Thread Tools
 
Search this Thread
 
Old 10 October 2002, 04:39 PM
  #1  
druddle
Scooby Regular
Thread Starter
 
druddle's Avatar
 
Join Date: Mar 2001
Location: Berkshire
Posts: 5,528
Likes: 0
Received 0 Likes on 0 Posts
Post

I have a ksh scrip that contains 60 or so of the following entries to create luns on a FibreCAT (Clariion)...

/opt/Navisphere/bin/navicli -h mccrfc1a bind r5 66 -rg 3 -wc 1 -rc 1 -sq bc -cap 1048576 -aa 1
/opt/Navisphere/bin/navicli -h mccrfc1a bind r5 67 -rg 3 -wc 1 -rc 1 -sq bc -cap 32505856 -aa 1

I want to echo each line before it executes, so it looks as follows....

echo "/opt/Navisphere/bin/navicli -h mccrfc1a bind r5 66 -rg 3 -wc 1 -rc 1 -sq bc -cap 1048576 -aa 1"
/opt/Navisphere/bin/navicli -h mccrfc1a bind r5 66 -rg 3 -wc 1 -rc 1 -sq bc -cap 1048576 -aa 1
echo "/opt/Navisphere/bin/navicli -h mccrfc1a bind r5 67 -rg 3 -wc 1 -rc 1 -sq bc -cap 32505856 -aa 1"
/opt/Navisphere/bin/navicli -h mccrfc1a bind r5 67 -rg 3 -wc 1 -rc 1 -sq bc -cap 32505856 -aa 1

How can i do this easily with the command line in vi ????

Cheers

Dave
Old 10 October 2002, 05:33 PM
  #2  
Sheepsplitter
Scooby Regular
 
Sheepsplitter's Avatar
 
Join Date: Nov 2001
Posts: 1,072
Likes: 0
Received 0 Likes on 0 Posts
Post

You can do it pretty easily with awk.
Try this.

Stick the lines of your program in a file, call it x (in our example).

i.e x contains:-
/opt/Navisphere/bin/navicli -h mccrfc1a bind r5 66 -rg 3 -wc 1 -rc 1 -sq bc -cap 1048576 -aa 1
/opt/Navisphere/bin/navicli -h mccrfc1a bind r5 67 -rg 3 -wc 1 -rc 1 -sq bc -cap 32505856 -aa 1


Now run the following shell command:-
cat x |awk '{print "echo "$0; print $0;}' > newfile


You should now find newfile contains exactly what you want.
i.e


echo /opt/Navisphere/bin/navicli -h mccrfc1a bind r5 66 -rg 3 -wc 1 -rc 1 -sq bc -cap 1048576 -aa 1
/opt/Navisphere/bin/navicli -h mccrfc1a bind r5 66 -rg 3 -wc 1 -rc 1 -sq bc -cap 1048576 -aa 1
echo /opt/Navisphere/bin/navicli -h mccrfc1a bind r5 67 -rg 3 -wc 1 -rc 1 -sq bc -cap 32505856 -aa 1
/opt/Navisphere/bin/navicli -h mccrfc1a bind r5 67 -rg 3 -wc 1 -rc 1 -sq bc -cap 32505856 -aa 1


Or if you prefer in Perl:-


#!/usr/bin/perl


open(FILE,"<x") or die("Cant find file\n");

while (<FILE&gt
{
print "echo $_";
print $_;
}
close(FILE);





Mind you if all you wanted to do is see which line is being exectuted and when then the easy way is to put a
#!/bin/sh -x

at the top of your script and it well echo each line it executes, maybe this is a more elegant solution for you?

Hope one of these solutions helps.





[Edited by Sheepsplitter - 10/10/2002 5:51:24 PM]
Old 10 October 2002, 05:52 PM
  #3  
druddle
Scooby Regular
Thread Starter
 
druddle's Avatar
 
Join Date: Mar 2001
Location: Berkshire
Posts: 5,528
Likes: 0
Received 0 Likes on 0 Posts
Post

Good thinking Batman !!

Replaced #!/bin/sh with #!/bin/sh -x and job done.

Cheers

Dave
Old 11 October 2002, 12:11 PM
  #4  
druddle
Scooby Regular
Thread Starter
 
druddle's Avatar
 
Join Date: Mar 2001
Location: Berkshire
Posts: 5,528
Likes: 0
Received 0 Likes on 0 Posts
Post

Sheepsplitter

How will i get the " at the end of the echo line with the perl script ?

Dave
Old 11 October 2002, 12:27 PM
  #5  
Sheepsplitter
Scooby Regular
 
Sheepsplitter's Avatar
 
Join Date: Nov 2001
Posts: 1,072
Likes: 0
Received 0 Likes on 0 Posts
Post

To use the " in any Perl script precede it with the backslash character to tell the Perl interpreter to take it literally.

i.e
print "echo \"quotes\"";


Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Pro-Line Motorsport
ScoobyNet General
9
28 September 2015 09:48 PM
Ravimal3
General Technical
9
22 September 2015 06:44 AM
Blow Dog
Non Scooby Related
4
16 September 2001 12:22 PM
SimonH
ScoobyNet General
18
19 March 2001 11:35 AM
ALT3ZZA
ScoobyNet General
2
09 May 2000 01:45 PM



Quick Reply: Urgent vi/sed help pls



All times are GMT +1. The time now is 02:18 PM.