If the data is in a variable as in:
you can get the last field with:
and the next to the last field with:
and to see the results:
which with var set as shown above will print:
P.S.: I hadn't seen your last post (post #3) when I originally posted this and didn't know what OS you are using. The above suggestion will work with /usr/xpg4/bin/sh, ksh, or bash; but not /bin/sh on Solaris 10 systems. This will work with any shell that conforms to the POSIX standards. If some of your old systems were built before 1993, you may need to use expr to split substrings out of your variables unless you know how many underscores appear in your variables before you start splitting out fields from them.
Last edited by Don Cragun; 11-27-2017 at 07:34 PM..
Reason: Add postscript.
This User Gave Thanks to Don Cragun For This Post:
I am executing a stored proc and sending the results in a log file. I then want to grab one result from the output parameters (bolded below, 2) so that I can store it in a variable which will then be called in another script. There are more details that get printed in the beginning of the log file,... (3 Replies)
Hello all I hope someone can help me. I am trying to convert something I wrote in C to bash.
But how do I go about reading more than one item at a time in a for loop?
i have been using this format for the loops in the bash script i have been building.
e.g.
for word in `cat -s... (4 Replies)
I have a process that is running locally on the machine.
When you telnet to the process: telnet IP port, it automatically returns a string which shows the status of that process.
Something like this:
# telnet IP Port
Trying 127.0.0.1...
Connected to localhost (127.0.0.1).
Escape... (3 Replies)
ok, so a script i wrote spits out an output like the below:
2,JABABA,BV=114,CV=1,DF=-113,PCT=99.1228%
as you can see, each field is separated by a comma. now, how can I get rid of the first field and ONLY show the rest of the fields.
meaning,
i want to get rid of the "2,", and... (3 Replies)
Hi,
I am trying to implement a server monitoring dashboard using cgi scripting. I am planning to run the necessary unix scripts from the web page using cgi. This method works fine for standard unix commands but I am unable to run some external unix commands (like swadm show_processes, swadm... (9 Replies)
Hi,
my script is setting a variable with value and this variable is present in my another command that is coming from external file and this command is internally called after this variable is set. but while execution of this command, the value is not retrieved properly.
say,
my script... (5 Replies)
Hello everyone,
I am doing some sort of analysis for some data about organic solvents, and I have a problem with writing a command to do this:
Here's a sample of my file:
1 ethanol
2 methanol
3 methanol/ethanol
4 ethanol/methanol
5 ethanol/DMF
6 ethyl... (6 Replies)
I have several .csv files containing data like this:
field_1;field_2;date;comment;amount;
I want to extract the 3 last fields and load them in a database.
my input_file = "/dir/file.csv";
my output_file = "/dir/file.sql";
open my $csv_file, '<', $input_file
or die "Can't... (1 Reply)
Hey guys, I am working on a script that needs to grab variables from a log file. The script will run morning 9 to 5pm and save variables for each run every hour, these results I will be aggregating at the end of the day.
I am thinking I will be placing the date on each entry in the log every... (7 Replies)