Sponsored Content
Top Forums Shell Programming and Scripting Calculate the length of the each variable and matches to the desired value Post 302563493 by rohit22hamirpur on Tuesday 11th of October 2011 11:22:13 AM
Old 10-11-2011
Calculate the length of the each variable and matches to the desired value

My script is currently doing two function and I want to add one more as pre the question.

Code:
 
echo -en "Enter the logmsg="
read logmsg
logmsg1=${logmsg%%|*};
logmsg_len2=$(echo ${logmsg} | awk '{print $2}');
logmsg_suffix="|";
Char()
{
#echo $logmsg1
echo $logmsg1 | tr ',' '\n' | awk '{if($0~/^D/||/^S/) {print $0" starts"} else {print " Please check your input(e.g. Start it with D or S)";exit;}}'
}
Pipe()
{
if [[  "${logmsg_len2}" != "${logmsg_suffix}" ]]; then
                 echo -e "error use | symbol"
                 exit 1;
     else
   echo "success"
 fi
}
Char
Pipe





This is the complete string which I am using in the script to get the desired results

D0000,D12345,S1234,D12345 | KestrelPrdV2_0.build.177 - svn 141115 tag as V2.0.0.14

Now my script will cut the left part (left from | symbol)
D0000,D12345,S1234,D12345

Now my question is how to calculate the length of the each varibale and also it should not more than 6 i.e. -le 6.Number of variables can be increases or decreases upto infinity.

Please let me know if more information require.
 

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies

2. Solaris

Calculate the length and add some string infront

Hi all, I have file having 4 coulmn like 9246309198,406655682,400009246309198 9246309198,9246309198,400009246309198 9246309198,9246309198,400009246309198 9246309198,9246309198,400009246309198 9246309198,406655682,400009246309198 9246309198,9246309198,400009246309198 I want to valid... (4 Replies)
Discussion started by: salaathi
4 Replies

3. Shell Programming and Scripting

How can use the perl or other command line to calculate the length of the character?

For example, if I have the file whose content are: >HWI-EAS382_30FC7AAXX:7:1:927:1368 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA >HWI-EAS382_30FC7AAXX:7:1:924:1373 ACGAACTTTAAAGCACCTCTTGGCTCGTATGCCGTC I want my output calculate the total length of nucleotide. So my output should look like this:... (1 Reply)
Discussion started by: patrick chia
1 Replies

4. Shell Programming and Scripting

Make variable length record a fixed length

Very, very new to unix scripting and have a unique situation. I have a file of records that contain 3 records types: (H)eader Records (D)etail Records (T)railer Records The Detail records are 82 bytes in length which is perfect. The Header and Trailer records sometimes are 82 bytes in... (3 Replies)
Discussion started by: jclanc8
3 Replies

5. Shell Programming and Scripting

changing a variable length text to a fixed length

Hi, Can anyone help with a effective solution ? I need to change a variable length text field (between 1 - 18 characters) to a fixed length text of 18 characters with the unused portion, at the end, filled with spaces. The text field is actually field 10 of a .csv file however I could cut... (7 Replies)
Discussion started by: dc18
7 Replies

6. Shell Programming and Scripting

Convert variable length record to fixed length

Hi Team, I have an issue to split the file which is having special chracter(German Char) using awk command. I have a different length records in a file. I am separating the files based on the length using awk command. The command is working fine if the record is not having any... (7 Replies)
Discussion started by: Anthuvan
7 Replies
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 06:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy