UNIX script URGENT!!!

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support UNIX script URGENT!!!
# 1  
Old 11-29-2010
UNIX script URGENT!!!

Code:
#!/bin/sh

INPUT () {
    echo "Please enter line number: "
    read LINE

    echo "Please enter column number that you want to modify: "
    read COLUMN

    head -$LINE dataf > line1;
    LINE=`expr $LINE + 1`
    head -$LINE dataf > line2;

    diff line1 line2 > tmp;
    sed -e 's/;/ /g' tmp > tmp2;
    COLUMN=`expr $COLUMN + 1`
    OLDV=`awk '{printf "%s\n",$'$COLUMN' ; }' tmp2`
    echo "The value is $OLDV \n"

    echo "Please enter new value of the column: "
    read NEWV
    sed -e 's/$OLDV/$NEWV/g' tmp2 > tmp3

}

OthersMod () {
    echo "Do you want to do other modifications [y/n]?"
    read ANS

while [ "$ANS" = y ] 
do

    INPUT
    OthersMod 

done
}


INPUT
OthersMod



This is the whole script. The problem is:
Code:
    echo "Please enter new value of the column: "
    read NEWV
    sed -e 's/$OLDV/$NEWV/g' tmp2 > tmp3

I can't change the old value to the new value. Any wrong with the script?? Please help.. THANKS!

Moderator's Comments:
Mod Comment use code tags, please!
# 2  
Old 11-29-2010
Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.


Thank you.

The UNIX and Linux Forums
This User Gave Thanks to DukeNuke2 For This Post:
# 3  
Old 11-29-2010
try having double quotes around the below sed command instead of single..
Code:
sed -e "s/$OLDV/$NEWV/g" tmp2 > tmp3

This User Gave Thanks to michaelrozar17 For This Post:
# 4  
Old 11-29-2010
Quote:
Originally Posted by michaelrozar17
try having double quotes around the below sed command instead of single..
Code:
sed -e "s/$OLDV/$NEWV/g" tmp2 > tmp3




I tried but it doesn't work. It gave me this:
sed: command garbled: s/
# 5  
Old 11-29-2010
Try :

Code:
sed 's/'"$OLDV"'/'"$NEW"'/g' tmp2 > tmp3

for me it works :

Code:
# a=t
# b=Z
# echo "toto tutu toto tatat test" | sed 's/'"$a"'/'"$b"'/g'
ZoZo ZuZu ZoZo ZaZaZ ZesZ

if it doesn't work, then try

Code:
eval sed -e 's/$OLDV/$NEW/g' tmp2 > tmp3

(the -e might be useless)

if nothing else works, you can give a try to this "useless backtick/echo award"

Code:
sed 's/'`echo "$OLDV"`'/'`echo "$NEW"`'/g' tmp2 > tmp3


Last edited by ctsgnb; 11-29-2010 at 05:01 AM..
# 6  
Old 11-29-2010
Quote:
Originally Posted by ctsgnb
Try :

Code:
sed 's/'"$OLDV"'/'"$NEW"'/g' tmp2 > tmp3

if it doesn't work, then try

Code:
sed -e 's/'`echo "$OLDV"`'/'`echo "$NEW"`'/g' tmp2 > tmp3

(the -e might be useless)

Code:
sed 's/'`echo "$OLDV"`'/'`echo "$NEW"`'/g' tmp2 > tmp3



It still doesn't work. Anyway, thanks for ur effort! Smilie
# 7  
Old 11-29-2010
Quote:
Originally Posted by beginner1988
I tried but it doesn't work. It gave me this:
sed: command garbled: s/
or just

Code:
eval "sed -e 's/$OLDV/$NEWV/g'" tmp2 > tmp3

Watch out for the double quote and simple quote !

Code:
# a=t
# b=Z
# echo "toto tutu toto tatat test" | eval "sed 's/$a/$b/g'"
ZoZo ZuZu ZoZo ZaZaZ ZesZ
#

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

2. UNIX for Dummies Questions & Answers

Unix Command Urgent Help!

Hi All, i am new on this forum, can someone please answer the following questions as i am also new for UNIX, you help would be much appreciated: 1. How do you delete the full directory hierarchy? 2. How do you find out all process run by user Kamran ? 3. how would you extract something... (1 Reply)
Discussion started by: kami151
1 Replies

3. UNIX for Advanced & Expert Users

Need a unix script - very urgent

Hi All, I need a script that invokes the sql query every 14 days and send email Very Very urgent this one to me.... (6 Replies)
Discussion started by: bujjisveeru
6 Replies

4. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

5. HP-UX

HP Unix | Urgent Need Help

Hi, I'm new to unix and i'm using HP Unix I tried the following and getting error like 1. $sam sh:sam not found 2.Also i want to monitor/trace other user's command what they are using when am in to the same server Appreciate if any one help on this (4 Replies)
Discussion started by: msgobinathan
4 Replies

6. Shell Programming and Scripting

[urgent need help] unix script....

hi experts, i'm new in scripting unix i have some problem with my script below is shown my script : #!/bin/sh BASEDIR=/export/home/mapadm BINDIR=$BASEDIR/bin LOGDIR=$BASEDIR/log TDRDIR=$LOGDIR/TDR BACKUPDIR=/data/log export BASEDIR BINDIR LOGDIR TDRDIR BACKUPDIR YEAR=`date '+%Y'`... (21 Replies)
Discussion started by: bucci
21 Replies

7. Shell Programming and Scripting

Urgent Need your help --New to Unix

I am getting data like this in a flat file seg No Test A4 0000002595, A2, test ,Datatest Test, A1 0000002595, A1,SELF , Employed,1,2,3,400.50 Test, A2 0000002595, A2, test ,Data,eurp Test, A3 0000002595, A2, test ,Data I need to produce a flat file so that output file... (0 Replies)
Discussion started by: nikeng
0 Replies

8. Solaris

Urgent !!! - Script to Change passwords in unix

I have SunOs 5.8. I need to change password using a unix shell script. I have tried to pipe the passwords to the passwd command but does not work. Pls provide a script to change passwds of a list of users using a shell script. ( I have also tried crypt() but did not work) The flow of the... (2 Replies)
Discussion started by: tofani
2 Replies

9. UNIX for Dummies Questions & Answers

I am in urgent need of all UNIX-derivates...

Hi, could anybody name all the different UNIX versions, producer, historie, etc? need a short briefing... THX a lot in advance... Greetings, PatrickXXO (2 Replies)
Discussion started by: PatrickXXO
2 Replies

10. UNIX for Dummies Questions & Answers

Urgent UNIX problem for newbie!

I think someone hacked my UNIX account and I cannot get back into MY OWN account!!!!!! :( I was wondering if any of the experts here would be able to help me either get back into my account or change my password back to what it was or find out what it is now so I can get back in and change it. ... (2 Replies)
Discussion started by: speedemn
2 Replies
Login or Register to Ask a Question