# need solution for scripting

**URL:** <https://community.unix.com/t/need-solution-for-scripting/183754>\
**Category:** Shell Programming and Scripting\
**Created:** [January 30, 2008, 9:23pm UTC](https://community.unix.com/t/need-solution-for-scripting/183754 "2008-01-30T21:23:04Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![kkc](https://community.unix.com/letter_avatar/kkc/32/6_449c533f586939b6e5f246632a46421f.png) [@kkc](https://community.unix.com/u/kkc)\
**Post date:** [January 30, 2008, 9:23pm UTC](https://community.unix.com/t/need-solution-for-scripting/183754/1 "2008-01-30T21:23:04Z")

</div>

hi all,

i would like to add on the print command to prompt user to enter a value and store inside the variable name as $inName  
after that the value will replace the existing line for ${METRICA\_DIR}/TechnologyPacks/Spool/2030324032  
i'm new in scripting, could anyone give me some hint for sripting?

tmpfile=/tmp/tmpfile.$$

for file in loaderconfiguration\*.xml  
do  
sed 's|${METRICA\_DIR}/TechnologyPacks/Spool/2030324032|$inName|g' $file \> $tmpfile  
mv $tmpfile $file  
done

thanks

---

<div class="post-metadata">

**Author:** ![system](https://community.unix.com/uploads/default/original/2X/c/c7e9e16a595259edafe88615719d5c5dcda035c2.png) [@system](https://community.unix.com/u/system)\
**Post date:** [January 31, 2008, 12:11am UTC](https://community.unix.com/t/need-solution-for-scripting/183754/2 "2008-01-31T00:11:11Z")

</div>

Hi,

Iam new to Shell programming and i want to Display the same lines in a file which is appearing more than once.

Here is a file format,

WERTFRT|1234567890  
ASDFFGU|1230986545  
WERTFRT|1234567890  
CVBNMKL|7685645385

Here 1st and 3rd lines are same and i need to select and write it in to seperate file.  
please help me.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![summer\_cherry](https://community.unix.com/letter_avatar/summer_cherry/32/6_449c533f586939b6e5f246632a46421f.png) [@summer\_cherry](https://community.unix.com/u/summer_cherry)\
**Post date:** [January 31, 2008, 12:39am UTC](https://community.unix.com/t/need-solution-for-scripting/183754/3 "2008-01-31T00:39:55Z")

</div>

hi KKC,

please you double quote \<"\> instead of single quote \<'\> in your sed command, then it should be ok.

---

<div class="post-metadata">

**Author:** ![kkc](https://community.unix.com/letter_avatar/kkc/32/6_449c533f586939b6e5f246632a46421f.png) [@kkc](https://community.unix.com/u/kkc)\
**Post date:** [January 31, 2008, 1:03am UTC](https://community.unix.com/t/need-solution-for-scripting/183754/4 "2008-01-31T01:03:03Z")

</div>

> [@summer\_cherry](#):
>
> hi KKC,
> 
> please you double quote \<"\> instead of single quote \<'\> in your sed command, then it should be ok.

sorry i can't get you mean,  
i wanted add on such like

print "what is your directory : ";  
then the answer is storing to &inName

and the sed will replace the &inName to ${METRICA\_DIR}/TechnologyPacks/Spool/2030324032

sed 's|${METRICA\_DIR}/TechnologyPacks/Spool/2030324032|$inName|g' $file

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Karthikeyan\_113](https://community.unix.com/letter_avatar/karthikeyan_113/32/6_449c533f586939b6e5f246632a46421f.png) [@Karthikeyan\_113](https://community.unix.com/u/Karthikeyan_113)\
**Post date:** [January 31, 2008, 1:38am UTC](https://community.unix.com/t/need-solution-for-scripting/183754/5 "2008-01-31T01:38:07Z")

</div>

Hi KKC,

summer\_cherry was asking you to replace the single codes in the sed command with double codes.

```nohighlight
sed "s|${METRICA_DIR}/TechnologyPacks/Spool/2030324032|$inName|g" $file 

```

# ========== Thanks, Karthikeyan.

---

<div class="post-metadata">

**Author:** ![kkc](https://community.unix.com/letter_avatar/kkc/32/6_449c533f586939b6e5f246632a46421f.png) [@kkc](https://community.unix.com/u/kkc)\
**Post date:** [January 31, 2008, 1:46am UTC](https://community.unix.com/t/need-solution-for-scripting/183754/6 "2008-01-31T01:46:47Z")

</div>

> [@karthikeyan\_113](#):
>
> Hi KKC,
> 
> summer\_cherry was asking you to replace the single codes in the sed command with double codes.
> 
> ```plaintext
> sed "s|${METRICA_DIR}/TechnologyPacks/Spool/2030324032|$inName|g" $file 
> 
> ```
> 
> # ========== Thanks, Karthikeyan.

hi

🙂 thanks for the advise~, what is the different withe replace the single codes in the sed command with double codes?:eek:

many thanks

---

<div class="post-metadata">

**Author:** ![namishtiwari](https://community.unix.com/letter_avatar/namishtiwari/32/6_449c533f586939b6e5f246632a46421f.png) [@namishtiwari](https://community.unix.com/u/namishtiwari)\
**Post date:** [January 31, 2008, 1:48am UTC](https://community.unix.com/t/need-solution-for-scripting/183754/7 "2008-01-31T01:48:30Z")

</div>

You can do something like this--

echo "Enter the file/dir name"  
read file

then do the replacements here-  
sed "s|${METRICA\_DIR}/TechnologyPacks/Spool/2030324032|$inName|g" $file

Thanks

---

<div class="post-metadata">

**Author:** ![Karthikeyan\_113](https://community.unix.com/letter_avatar/karthikeyan_113/32/6_449c533f586939b6e5f246632a46421f.png) [@Karthikeyan\_113](https://community.unix.com/u/Karthikeyan_113)\
**Post date:** [January 31, 2008, 1:52am UTC](https://community.unix.com/t/need-solution-for-scripting/183754/8 "2008-01-31T01:52:06Z")

</div>

> [@kkc](#):
>
> hi
> 
> 🙂 thanks for the advise~, what is the different withe replace the single codes in the sed command with double codes?:eek:
> 
> many thanks

when you want the value of the variables to be substituted, you need to specify the expression in double codes.

# ========== Thanks, Karthikeyan.

---

<div class="post-metadata">

**Author:** ![Karthikeyan\_113](https://community.unix.com/letter_avatar/karthikeyan_113/32/6_449c533f586939b6e5f246632a46421f.png) [@Karthikeyan\_113](https://community.unix.com/u/Karthikeyan_113)\
**Post date:** [January 31, 2008, 1:55am UTC](https://community.unix.com/t/need-solution-for-scripting/183754/9 "2008-01-31T01:55:50Z")

</div>

> [@namishtiwari](#):
>
> You can do something like this--
> 
> echo "Enter the file/dir name"  
> read file
> 
> then do the replacements here-  
> sed "s|${METRICA\_DIR}/TechnologyPacks/Spool/2030324032|$inName|g" $file
> 
> Thanks

You getting the directory name in the variable file.  
and then you are using it as the filename ???  
I guess this will create confusion. Pls post with care.

# ========== Thanks, Karthikeyan.

---

<div class="post-metadata">

**Author:** ![kkc](https://community.unix.com/letter_avatar/kkc/32/6_449c533f586939b6e5f246632a46421f.png) [@kkc](https://community.unix.com/u/kkc)\
**Post date:** [January 31, 2008, 2:16am UTC](https://community.unix.com/t/need-solution-for-scripting/183754/10 "2008-01-31T02:16:42Z")

</div>

> [@namishtiwari](#):
>
> You can do something like this--
> 
> echo "Enter the file/dir name"  
> read file
> 
> then do the replacements here-  
> sed "s|${METRICA\_DIR}/TechnologyPacks/Spool/2030324032|$inName|g" $file
> 
> Thanks

:eek::eek:confusing.... can more clearly?

Thanks

---

<div class="post-metadata">

**Author:** ![kkc](https://community.unix.com/letter_avatar/kkc/32/6_449c533f586939b6e5f246632a46421f.png) [@kkc](https://community.unix.com/u/kkc)\
**Post date:** [January 31, 2008, 2:17am UTC](https://community.unix.com/t/need-solution-for-scripting/183754/11 "2008-01-31T02:17:19Z")

</div>

> [@karthikeyan\_113](#):
>
> when you want the value of the variables to be substituted, you need to specify the expression in double codes.
> 
> # ========== Thanks, Karthikeyan.

:D:Dthanks...

---

<div class="post-metadata">

**Author:** ![kkc](https://community.unix.com/letter_avatar/kkc/32/6_449c533f586939b6e5f246632a46421f.png) [@kkc](https://community.unix.com/u/kkc)\
**Post date:** [January 31, 2008, 9:53am UTC](https://community.unix.com/t/need-solution-for-scripting/183754/12 "2008-01-31T09:53:19Z")

</div>

tmpfile=/tmp/tmpfile.$$

for file in loaderconfiguration\*.xml  
do  
echo "what is the path:";  
read $path;  
sed "s|${METRICA\_DIR}/TechnologyPacks/Spool/2030324032|$path|g" $file \> $tmpfile  
mv $tmpfile $file  
done

any changes need to change which is highlighter with red colour...  
give some advise and hint please... 😕

many thanks...:)🙂

---

<div class="post-metadata">

**Author:** ![Karthikeyan\_113](https://community.unix.com/letter_avatar/karthikeyan_113/32/6_449c533f586939b6e5f246632a46421f.png) [@Karthikeyan\_113](https://community.unix.com/u/Karthikeyan_113)\
**Post date:** [January 31, 2008, 1:25pm UTC](https://community.unix.com/t/need-solution-for-scripting/183754/13 "2008-01-31T13:25:15Z")

</div>

Hi KKC,

are you getting any error ?  
anyprobem with the execution, why do you want to changethe highlighted part ?

# ========== Thanks, Karthikeyan.

---

<div class="post-metadata">

**Author:** ![KevinADC](https://community.unix.com/letter_avatar/kevinadc/32/6_449c533f586939b6e5f246632a46421f.png) [@KevinADC](https://community.unix.com/u/KevinADC)\
**Post date:** [January 31, 2008, 4:45pm UTC](https://community.unix.com/t/need-solution-for-scripting/183754/14 "2008-01-31T16:45:08Z")

</div>

> [@karthikeyan\_113](#):
>
> Hi KKC,
> 
> summer\_cherry was asking you to replace the single codes in the sed command with double codes.
> 
> ```plaintext
> sed "s|${METRICA_DIR}/TechnologyPacks/Spool/2030324032|$inName|g" $file 
> 
> ```
> 
> # ========== Thanks, Karthikeyan.

FYI:

"single codes" is correctly spelled "single quotes". 🙂

---

<div class="post-metadata">

**Author:** ![kkc](https://community.unix.com/letter_avatar/kkc/32/6_449c533f586939b6e5f246632a46421f.png) [@kkc](https://community.unix.com/u/kkc)\
**Post date:** [January 31, 2008, 8:17pm UTC](https://community.unix.com/t/need-solution-for-scripting/183754/15 "2008-01-31T20:17:10Z")

</div>

> [@karthikeyan\_113](#):
>
> Hi KKC,
> 
> are you getting any error ?  
> anyprobem with the execution, why do you want to changethe highlighted part ?
> 
> # ========== Thanks, Karthikeyan.

Hi Karthikeyan,

it doesn't replace this "${METRICA\_DIR}/TechnologyPacks/Spool/2030324032" with my input result.... anything do i miss out??😕

thanks  
kkc
