Trimming spaces from a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trimming spaces from a variable
# 1  
Old 12-13-2011
Trimming spaces from a variable

Hi guys,
when I take substring of a particular data using this command
var=substr($0,11,10)
it comes with spaces, when I am trying to trim the spaces it is not allowing me to do that.
Can you please help me out on that.
As I have to reverse the output of the variable also.

---------- Post updated at 07:50 AM ---------- Previous update was at 07:46 AM ----------

a=substr($0,11,10)
a1=`echo "${a}" | sed 's/ *$//'`

then it give me this error
The error context is
>>> a1=` <<<

Last edited by Scott; 12-13-2011 at 08:57 AM.. Reason: Duplicate post - Closed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trimming Spaces in Unix

Hi All, I am using following script to name the file base of some values #!/bin/sh sourcefile=$1 awk ' BEGIN{ n = 1; name = "FILEFILE12" n ".txt"; } { if (substr($0,1,10) == "FILEFILE12") { close (name) n++ a = substr($0,11,10); b = substr($0,21,5); name = b "_Src_" a ".txt" }... (6 Replies)
Discussion started by: manish8484
6 Replies

2. Shell Programming and Scripting

How can I stop the unix script from trimming extra spaces?

I have a file which contains certain records about users. the row length is always fixed to 205 characters. Now I want to read each record line from the file, substring some portion out of it and put into another file. But I have observed that my script is trimming the extra spaces I have used for... (4 Replies)
Discussion started by: Pramit
4 Replies

3. Shell Programming and Scripting

Variable with several values and spaces.

Hello all. I am a newb obviously and a bit stumped on this, so any help gratefully accepted. The script is extracting metadata from individual mp3 files, then (hopefully will be) sorting them into newly-created subdirectories. I have filtered out the relevant metadata and have the album names... (8 Replies)
Discussion started by: spoovy
8 Replies

4. Shell Programming and Scripting

trimming out spaces in solaris

friends, I have a script in solaris 10 SPARC system which is like this date '+Time: %m/%d/%y %H:%M:%S' echo " GDBRR GDLRR GDBWR GDLWR GDRRR GDRWR " sar -b 10 10 |/usr/xpg4/bin/awk '!/Average/ && !/SunOS/ && !/bread/ {$1="";T=$2;T1=$3;T2=$5;T3=$6;T4=$8;T5=$9}{print(T"\t",... (1 Reply)
Discussion started by: achak01
1 Replies

5. Shell Programming and Scripting

trimming trailing slashes in variable

I'm using this thread as an example, but can't seem to apply it to my situation. I'm trying to strip the trailing slash (/) from an input argument. Here's a snippet of my command line input and the troublesome code: $ script_name -s "../pathname/dir/" snip 8< ... while getopts :s:... (5 Replies)
Discussion started by: ricksj
5 Replies

6. UNIX for Advanced & Expert Users

Trimming the spaces

Hi, How can I remove the unwanted spaces in the line. 123456 789 ABC DEF. - I wanna remove the sapces in this line, I need the output 123456789ABCDEF. Pls help me...... (3 Replies)
Discussion started by: sharif
3 Replies

7. Shell Programming and Scripting

trimming white spaces

I have a variable that calls in a string from txt file. Problem is the string comes with an abundance of white spaces trailing it. Is there any easy way to trim the tailing white spaces off at the end? Thanks in advance. (9 Replies)
Discussion started by: briskbaby
9 Replies

8. Solaris

spaces trimming while assigning to a variable

Hi my lovely friends, Im writing one pgm in which i trying to assign some values like $var='Jun 6' but if i do echo of this $var will trim the spaces expect one space. $echo $var $Jun 6 But if var='Jun 28', then this will works fine $echo $var $Jun 28 this is required to exctract... (2 Replies)
Discussion started by: Lokesha
2 Replies

9. Shell Programming and Scripting

Variable containing spaces

Hi, my var is: PATH_LOG=/opt/WebSphere/CR Comune Roma.log a filename which contains blank chars. How can I call it from prompt ? Ex: ls $PATH_LOG or cat $PATH_LOG tks, Carmen- (2 Replies)
Discussion started by: Carmen123
2 Replies

10. 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
Login or Register to Ask a Question
ERUBIS(1)							   User Commands							 ERUBIS(1)

NAME
erubis - eRuby style template engine for multiple languages SYNOPSIS
erubis [..options..] [file ...] DESCRIPTION
Embedded templating engine for multiple languages. Erubis will take a template file as input and output code to convey that data in the language specified. The following output languages are supported: * Ruby * PHP * C * Java * Scheme * Perl * JavaScript OPTIONS
-h, --help help -v version -x show converted code -X show converted code, only ruby code and no text part -N numbering: add line numbers (for '-x/-X') -U unique: compress empty lines to a line (for '-x/-X') -C compact: remove empty lines (for '-x/-X') -b body only: no preamble nor postamble (for '-x/-X') -z syntax checking -e escape (equal to '--E Escape') -p pattern embedded pattern (default '<% %>') -l lang convert but no execute (ruby/php/c/java/scheme/perl/js) -E e1,e2,... enhancer names (Escape, PercentLine, BiPattern, ...) -I path library include path -K kanji kanji code (euc/sjis/utf8) (default none) -c context context data string (yaml inline style or ruby code) -f datafile context data file ('*.yaml', '*.yml', or '*.rb') -T don't expand tab characters in YAML file -S convert mapping key from string to symbol in YAML file -B invoke 'result(binding)' instead of 'evaluate(context)' --pi=name parse '<?name ... ?>' instead of '<% ... %>' supported properties: * (common) --escapefunc=nil : escape function name --pattern="<% %>" : embed pattern --trim=true : trim spaces around <% ... %> --preamble=nil : preamble (no preamble when false) --postamble=nil : postamble (no postamble when false) --escape=nil : escape expression or not in default * (basic) * (pi) --pi="rb" : PI (Processing Instrunctions) name --embchar="@" : char for embedded expression pattern('@{...}@') * ruby * php * c --indent="" : indent spaces (ex. ' ') --out="stdout" : output file pointer name * java --indent="" : indent spaces (ex. ' ') --buf="_buf" : output buffer name --bufclass="StringBuffer" : output buffer class (ex. 'StringBuilder') * scheme --func="_add" : function name (ex. 'display') * perl --func="print" : function name * javascript --docwrite=true : use 'document.write()' when true EXAMPLES
Run 'erubis -l php example.ephp' to convert the embedded document to php code. example.ephp: <?xml version="1.0"?> <html> <body> <p>Hello <%= $user %>!</p> <table> <tbody> <% $i = 0; %> <% foreach ($list as $item) { %> <% $i++; %> <tr bgcolor="<%= $i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>"> <td><%= $i %></td> <td><%== $item %></td> </tr> <% } %> </tbody> </table> </body> </html> SEE ALSO
http://rubyforge.org/projects/erubis/ erubis 2.6.2 January 2009 ERUBIS(1)