String variable question help plz


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers String variable question help plz
# 1  
Old 12-31-2011
String variable question help plz

Dear all,
I have problem with string variable, I want to write script which do the following

read x
x="part1=part2"

then I want to sub the x variable for
x1="part1"
and
x2="part2"

Is that possible ??
# 2  
Old 12-31-2011
Code:
x1=$( echo $x | cut -f1 -d"=" )
x2=$( echo $x | cut -f2 -d"=" )

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 3  
Old 12-31-2011
thank you its working, but if I want to return the column number in grep
ex:
a,b,c,d,e,f,g # in file1
grep d file1
I want output 4
# 4  
Old 12-31-2011
Code:
awk -F, '{ for(i=1;i<=NF;i++){if(srch==$i){print i;exit}} }' srch="d" infile

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 5  
Old 12-31-2011
Thank you very much, I am new in script Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Check if string variable is a subset of another string variable

Below is my ksh shell script where I need to check if variable fileprops is a subset of $1 argument. echo "FILE PROPERTY: $fileprops" echo "PARAMETER3: $1" if ; then echo "We are Good. $line FILE is found to be INTACT !! " else echo... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. UNIX for Dummies Questions & Answers

Comparing a String variable with a string literal in a Debian shell script

Hi All, I am trying to to compare a string variable with a string literal inside a loop but keep getting the ./testifstructure.sh: line 6: #!/bin/sh BOOK_LIST="BOOK1 BOOK2" for BOOK in ${BOOK_LIST} do if then echo '1' else echo '2' fi done Please use next... (1 Reply)
Discussion started by: daveu7
1 Replies

3. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

4. Homework & Coursework Questions

Plz Help Me in This question in Shell Programming

2- Write a bash shell script filestatic. The script should examine the number files in directories given as arguments (parameters) to this script. a. if one argument is given, the script should count and report the number of files in this directory. Only regular files should be counted, not... (1 Reply)
Discussion started by: tahseen_22334
1 Replies

5. Shell Programming and Scripting

Plz Help Me in This question in Shell Programming

2- Write a bash shell script filestatic. The script should examine the number files in directories given as arguments (parameters) to this script. a. if one argument is given, the script should count and report the number of files in this directory. Only regular files should be counted, not... (1 Reply)
Discussion started by: tahseen_22334
1 Replies

6. Shell Programming and Scripting

Appending string, variable to file at the start and string at end

Hi , I have below file with 13 columns. I need 2-13 columns seperated by comma and I want to append each row with a string "INSERT INTO xxx" in the begining as 1st column and then a variable "$node" and then $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13 and at the end another string " ; COMMIT;" ... (4 Replies)
Discussion started by: Vaddadi
4 Replies

7. Shell Programming and Scripting

Read string from a file,plz help me to check

#!/usr/bin/ksh exec 0<property while read newReceiveDir do if then sed -e 's//home/joshua/bodi/data/receive/{$newReceiveDir:25}/g/' mp_validate.sh >| mp_validate.sh elif then sed -e 's//home/joshua/bodi/data/temp/{$newReceiveDir:22}/g/' mp_validate.sh >| mp_validate.sh ... (1 Reply)
Discussion started by: joshuaduan
1 Replies

8. Shell Programming and Scripting

Plz help with this Question

Hi, I have to submit my Assignment on 27th and am new to Unix. Please help me with this question. I have attached the questions I would eagerly wait for response :( ..m really tensed :confused: thanks Monica Email removed (1 Reply)
Discussion started by: monicajogi80
1 Replies

9. UNIX for Dummies Questions & Answers

A question that need an answer Plz

I'm with FreeBSD 4.6.2, and i would like to know how to install this ports : ftp://ftp.freebsd.org/pub/FreeBSD/branches/-current/ports/net/kmerlin There's no .tgz so i can't do the pkg_add command. Can you please help me??? Thank You. :) Erythro73 (6 Replies)
Discussion started by: Erythro73
6 Replies

10. UNIX for Dummies Questions & Answers

plz Help How should I configure cc compiler output file plz help???

i.e configuration of C compiler :confused: (4 Replies)
Discussion started by: atiato
4 Replies
Login or Register to Ask a Question