replace <Address> with a var input by user


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replace <Address> with a var input by user
# 1  
Old 06-16-2005
replace <Address> with a var input by user

Hi, All
here is not a full version script, just post a sample.

Code:
#/bin/bash
read -p 'Addr: ' addr
sed 's/<Address>/'"$addr"'/' pf.mod>$1

If the input string include `/', sed will return error message. I know that s/// can be replaced with s::: or s!!!, etc, but the input var can accept everything.

So, I need your help to kick out the weakness of this script.
BTW: using sed is not a requirment, but I really hope that sed can do it.

Bob

Last edited by r2007; 06-16-2005 at 12:10 PM..
# 2  
Old 06-16-2005
You can try as,

#/bin/bash
read -p 'Addr: " addr
awk '{ if ( $1 ~ "<Address>") { print address } }' address=$addr <filename>

hth.
# 3  
Old 06-16-2005
muthukumar, thank you for your reply. I am not doing a full test, but I think it works after modifying the code according to the pf.mod contents that I am not post at last time.

here is the pf.mod.
Code:
hello <customer> blah blah
...
...
blah blah ...<address> blah blah
...
...
Address: <address>
...
...

# 4  
Old 06-16-2005
The reason why your original script fails is that sed interprets some characters as metacharacters. Escape them prior to feeding them to sed (by setting a "\" in fromt of them) and everything will work out fine:

Code:
addr="$(print - "$addr" | sed 's/\//\&/g')"

Hope this helps.

bakunin
# 5  
Old 06-16-2005
Thank you. Well, the world is not perfect Smilie , I am ready to use AWK or escape the backslash at begining.
Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Log all the commands input by user at real time in /var/log/messages

Below is my script to log all the command input by any user to /var/log/messages. But I cant achieve the desired output that i want. PLease see below. function log2syslog { declare COMMAND COMMAND=$(fc -ln -0) logger -p local1.notice -t bash -i -- "$USER:$COMMAND" } trap... (12 Replies)
Discussion started by: invinzin21
12 Replies

2. Shell Programming and Scripting

User input and run awk using the input

I am trying to allow a user to enter in text and then store that text in a variable $gene to run in an awk command in which those values are used to run some calculations. I am getting syntax errors however, when I try. Thank you :). The awk runs great if it is a pre-defined file that is used,... (7 Replies)
Discussion started by: cmccabe
7 Replies

3. Shell Programming and Scripting

Script interacts with user , based on user input it operates

i have a script which takes input from user, if user gives either Y/y then it should continue, else it should quit by displaying user cancelled. #!/bin/sh echo " Enter your choice to continue y/Y OR n/N to quit " read A if then echo " user requested to continue " ##some commands... (7 Replies)
Discussion started by: only4satish
7 Replies

4. Shell Programming and Scripting

Find and replace folder of files with $var

I want to scan through all the files in the folder and replace all instances of $file_X within the file with the variable $X defined in my bash script on my debian 6.0 install. For example, if the file contains $file_dep I want it to be replaced with the value of the variable $dep defined in my... (1 Reply)
Discussion started by: Spadez
1 Replies

5. Shell Programming and Scripting

How to get the user input recursively until the user provides valid input

Hi, echo "Enter file name of input file list along with absolute path : " read inputFileList if then for string in `cat inputFileList` do echo $string done else echo " file does not exist" fi From the above code, if the user enters a invalid file... (1 Reply)
Discussion started by: i.srini89
1 Replies

6. Shell Programming and Scripting

how to display an error if input value is not an IP address??

Dears, I need your assistance, I'm creating a shell script to read the IP address of a server and i would like to display an error message in red if the entered value is not an IP. any ideas how can i do it?:confused: #!/bin/sh echo "Please enter the server IP address: \c" read IPadd... (3 Replies)
Discussion started by: Dendany83
3 Replies

7. Homework & Coursework Questions

[Scripting]Find & replace using user input then replacing text after

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: (o) Checkout an auto part: should prompt the user for the name of the auto part and borrower's name: Name:... (2 Replies)
Discussion started by: SlapnutsGT
2 Replies

8. Shell Programming and Scripting

find & replace with user input

Trying to create a script/executable to replace "abc" text string in "myfile.htm" with input from a pop-up field. For example, launch this thing and a prompt is popped up asking the user to input what "abc" should be replaced with, then it inserts what the user inputs in place of abc in the... (3 Replies)
Discussion started by: mike909
3 Replies

9. UNIX for Dummies Questions & Answers

Panic kernal-mode address fault on user address 0x14

:) Firstly Hi all!!, im NEW!! and on here hoping that someone might be able to offer me some help... i have a server that keeps crashing every few days with the error message: PANIC KERNAL-MODE ADDRESS FAULT ON USER ADDRESS 0X14 KERNAL PAGE FAULT FROM (CS:EIP)=(100:EF71B5BD) EAX=EF822000... (10 Replies)
Discussion started by: Twix
10 Replies

10. Shell Programming and Scripting

Replace var if conditon is met

HPUX 11i v2 #!/bin/sh Hi all. I am using a read to split a file into variables: cat filename | while read VAR1 VAR2 ETC ETC then a do to work each line $VAR2 is always 9 characters. If the first character is NOT an A or a 9, then I need to mask the first 5 characters with *****.... (7 Replies)
Discussion started by: lyoncc
7 Replies
Login or Register to Ask a Question