Urgent vi/sed help pls
#1
Scooby Regular
Thread Starter
Join Date: Mar 2001
Location: Berkshire
Posts: 5,528
Likes: 0
Received 0 Likes
on
0 Posts
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
/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
#2
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>
{
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]
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>
{
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]
Thread
Thread Starter
Forum
Replies
Last Post
Ravimal3
General Technical
9
22 September 2015 06:44 AM
Blow Dog
Non Scooby Related
4
16 September 2001 12:22 PM