Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Manipulate string in shell script

Tags
shell scripts, string manipulation, unix shell scripting

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 04-17-2011
Manipulate string in shell script

I am writing a shell script for some purpose. I have a variable of the form -- var1 = "policy=set policy"

Now I need to manipulate the variable var to get the string after index =. that is i should have "set polcy". Also I need to to this for many other variables where the value of "=" is not constant. Like

var2 = "bgroup = set bgroup port"
var3 = "utm = set security utm"
Please give an idea how to do it.
# 2  
Old 04-17-2011
You can use the cut command for this

Code:
var1="policy=set policy"
var1value=`echo $var1 | cut -d"=" -f2`

Note : There should not be any space between the shell variable and it assignment value.

var1 = something => incorrect
var1=something => correct

regards,
Ahamed

Last edited by ahamed101; 04-17-2011 at 03:34 AM.. Reason: code tags
# 3  
Old 04-17-2011
Hi

Could you elaborate what exactly you need.
# 4  
Old 04-17-2011
#!/bin/bash
#
bash code:
  1. #!/bin/bash
  2. var2="bgroup = set bgroup port"
  3. var3="utm = set security utm"
  4. echo "$var2 --> '${var2# = }'"
  5. echo "$var3 --> '${var3# = }'"
  6. # You can also
  7. for V in var2 var3; do
  8.     echo "${!V} --> '${!V# = }'"
  9. done#
The Following User Says Thank You to frans For This Useful Post:
Dev_Sharma987 (04-17-2011)
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to manipulate string in line? baris35 Shell Programming and Scripting 8 2 Weeks Ago 05:04 PM
Need help to manipulate data using script nith_anandan Shell Programming and Scripting 8 11-28-2013 10:55 PM
Manipulate XML File Continous STRING by each Order Line using SHELL Pete.kriya Shell Programming and Scripting 3 08-08-2013 04:11 PM
Shell script to manipulate files vedanta UNIX for Advanced & Expert Users 0 04-17-2013 04:19 PM
nawk script to manipulate txt file ment0smintz Shell Programming and Scripting 15 10-03-2012 02:56 AM
Find string in one file and manipulate other pparthiv Shell Programming and Scripting 3 07-16-2012 02:09 AM
Comparing a String variable with a string literal in a Debian shell script daveu7 UNIX for Dummies Questions & Answers 1 03-14-2012 08:37 AM
Script to manipulate contents of clipboard js8765 Shell Programming and Scripting 3 12-05-2010 11:44 AM
Shell script to manipulate a file deo_kaustubh Shell Programming and Scripting 2 08-09-2010 08:41 PM
Shell script to manipulate a message count for the same IP @ diff session gobinath Shell Programming and Scripting 1 05-28-2008 03:13 PM


All times are GMT -4. The time now is 07:49 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password