The last argument contains spaces, how do I get it into a variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting The last argument contains spaces, how do I get it into a variable?
# 8  
Old 10-24-2011
The simple way is to post the sample source data, and your expect output
# 9  
Old 10-24-2011
Could you be more exact with your example input? When you say $14 and $15 do you mean what awk thinks they are, or what they''re supposed to be?

Also, null and spaces are not the same thing (and the number of spaces is important as well).
# 10  
Old 10-24-2011
Thanks for your interest guys:

Below is the script instruction intended to recuperate Arguments 13 (4 cars) and 14 (50 cars).
Arguments 1-12 are variable length and separated by a space.

V_SEVERITY=`echo ${*} | awk '{print substr($13,1,4)}'`
V_INFO=`echo ${*} | awk '{print substr($13,5,50)}'`

Case 1:
========
Code:
${*} = "UNIV ABORTED JOB  GS1 VMSDLCEREF 2011/10/24 11:59 0000183 0000000 UNIV56 X vmsdlceref                                                        "

Note the quotes are mine.

Result of echo:
V_SEVERITY=""
V_INFO=""

Case 2:
========
Code:
${*} = "UNIV ABORTED JOB  GS2 VMSDLCEREF 2011/10/24 12:08 0000184 0000000 UNIV56 X vmsdlceref 3333 
                                                  "

V_SEVERITY="3333"
V_INFO=""

Case 3:
========
Code:
${*} = "UNIV ABORTED JOB  GS3 VMSDLCEREF 2011/10/24 12:12 0000185 0000000 UNIV56 X vmsdlceref      12345678901234567890123456789012345678901234567890"

V_SEVERITY="1234"
V_INFO="5678901234567890123456789012345678901234567890"

Case 4:
========
Code:
${*} = "UNIV ABORTED JOB  GS4 VMSDLCEREF 2011/10/24 12:14 0000186 0000000 UNIV56 X vmsdlceref 9999 one two three four five six seven eight nine ten X"

V_SEVERITY="9999"
V_INFO=""

Sorry in Case 1 the argument string has 56 spaces at the end and in Case 2 51, the forul software seems to trim the spaces.

Zagga

Last edited by zagga; 10-24-2011 at 07:43 AM.. Reason: spaces disappeared
# 11  
Old 10-24-2011
Try this...
Code:
V_SEVERITY=$(echo $*| awk 'NF>=13{if($13 ~ /[0-9]*/)print substr($13,0,4)}')
V_INFO=$(echo $*| awk 'NF>=13{if($13 ~ /[0-9]*/)print substr($13,5)}')

--ahamed

Last edited by ahamed101; 10-24-2011 at 07:42 AM..
# 12  
Old 10-24-2011
Use code tags.

How many spaces are there after vmsdlceref in case 3?
# 13  
Old 10-24-2011
Ahamed, CarloM

I still have the same problem in cases 3 and 4 using Ahamed's proposed solution:

If argument 13 is empty, there will be FS+4 spaces + FS (ie 6 spaces in all).
In case three, the variable V_SEVERITY recuperates the 1st four characters of ARG14 where it should contain all spaces.

Zagga
# 14  
Old 10-24-2011
I am confused now!
Whatever you have posted, isn't that you want? or are those the error conditions? Please provide some more clarity!

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check for spaces in input argument!

Hi guys, I have created a csh script which allows user to pass input argument with the script like: cluster_on_lev3.csh -t <value> -p <value> Example: cluster_on_lev3.csh -t 2.3 -p 0.05 Now I want to create an error code where if user passes input argument without spaces , the code... (16 Replies)
Discussion started by: dixits
16 Replies

2. Shell Programming and Scripting

Passing variable as an argument to another script

Hi, I am trying to pass a variable as an argument to another script. While substitution of variable, I am facing a problem. varaiable "a" value should be -b "FPT MAIN". When we pass "a" to another script, we are expecing it to get substitue as ./test.sh -b "FPT MAIN". But, it is getting... (9 Replies)
Discussion started by: Manasa Pradeep
9 Replies

3. Shell Programming and Scripting

Variable passed as argument

I have a script. #!/bin/sh cur_$1_modify_time=Hello echo "cur_$1_modify_time" When I run like sh /root/script1 jj I expect value "Hello" being assigned to variable "cur_jj_modify_time" and output being "Hello" ie echoing $cur_jj_modify_time But the output comes as # sh... (3 Replies)
Discussion started by: anil510
3 Replies

4. Shell Programming and Scripting

pass variable as sar argument

I am trying to get the details of iowait for last hour using sar. When I give date as argument it works. # sar -u -s 22:24:00 -e 23:24:00 Linux 2.6.35.13-26 (XX.server.com) 04/11/2012 10:30:03 PM CPU %user %nice %system %iowait %idle 10:40:04 PM all 5.03 ... (2 Replies)
Discussion started by: anil510
2 Replies

5. Shell Programming and Scripting

Pass command line argument to variable

Hi, I had written a shell script to pass command line argument to variable in a function. Here is my code: main if ; then .$1 echo $1 get_input_file else echo "input file $1 is not available" fi get_input_file() { FILE = "$1" echo $FILE } (10 Replies)
Discussion started by: Poonamol
10 Replies

6. Shell Programming and Scripting

about an argument with variable in sed

hi all let say I run the ./xxx.bash x x x x or ./xxx.bash x x x or ./xxx.bash x x x x x the last argument always a filename the last arugment filename format is 5-10-22.txt my question is how can I put this arugment into variable and I can use it in sed or any other way that i can use I... (1 Reply)
Discussion started by: yuesko
1 Replies

7. Shell Programming and Scripting

how to assign script argument to a variable

I have a script file. test.sh I am running it by command sh test.sh 10102004 where 10102004 is the script argument. I wan to assign this 10102004 to a variable. How can i do this? I tried &1 and awks ARGV its not working :( (2 Replies)
Discussion started by: rohankit
2 Replies

8. Shell Programming and Scripting

problem with spaces and argument parsing

public class HelloWorld { public static void main(String args) { System.out.println("Welcome, master"); } } and I compiled using javac HelloWorld.java ] Suppose that I execute the following command directly from the shell: java -XX:OnError="gdb - %p" HelloWorld Then it works... (8 Replies)
Discussion started by: fabulous2
8 Replies

9. Shell Programming and Scripting

Strip leading and trailing spaces only in a shell variable with embedded spaces

I am trying to strip all leading and trailing spaces of a shell variable using either awk or sed or any other utility, however unscuccessful and need your help. echo $SH_VAR | command_line Syntax. The SH_VAR contains embedded spaces which needs to be preserved. I need only for the leading and... (6 Replies)
Discussion started by: jerardfjay
6 Replies

10. Shell Programming and Scripting

Passing the command line argument in a variable

Hi, I am new to unix. Is their a way to pass the output of the line below to a variable var1. ls -1t | head -1. I am trying something like var1=ls -1t | head -1, but I get error. Situation is: I get file everyday through FTP in my unix box. I have to write a script that picks up first... (1 Reply)
Discussion started by: rkumar28
1 Replies
Login or Register to Ask a Question