Reading from input with sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading from input with sed
# 1  
Old 09-29-2010
Reading from input with sed

I am trying to edit a file in shell script using sed. I need to get the input from command line
suppose

script.sh
Code:
sed"/s place=/place=california/g" > /root/user/mark.txt
echo " place changed "

the above code searches for string place in the file mark.txt and replaces with place= california.

Now I need california to be entered manually when it runs the script and return back to the next commands in the script

supose when I run the script it should run as follows

enter place = california (user should give the input)

Last edited by Scott; 09-29-2010 at 07:03 PM.. Reason: Code tags
# 2  
Old 09-29-2010
This?
shell code:
  1. read - p "enter place : " VALUE
  2. sed "s/place=/place=$VALUE/g" /root/user/mark.txt # for test purpose
  3. # sed -i "s/place=/place=$VALUE/g" /root/user/mark.txt # if you want to modify the file
  4. echo " place changed to $VALUE"
Note that if you alread have place=Arizona and that you enter California, it will output place=CaliforniaArizona.

Last edited by frans; 09-30-2010 at 03:23 AM.. Reason: removed non-working bold tags, corrected sed syntax
# 3  
Old 09-29-2010
above code mix the html code and wrong way to use s function in sed. Here is the correction.
Code:
VALUE="california"      # or use command read as above 
sed "s/place=/place=$VALUE/g" /root/user/mark.txt  > other_output.txt
echo " place changed to $VALUE"

# 4  
Old 09-29-2010
I think the code send by frans is fine.But can you please test it and resend. its not working
# 5  
Old 09-29-2010
Quote:
Originally Posted by sriki32
I think the code send by frans is fine.But can you please test it and resend. its not working
Fine? I don't think so.

Are you really test frans's code? I don't think you can get right result.
# 6  
Old 09-30-2010
Quote:
Originally Posted by rdcwayx
Fine? I don't think so.
Are you really test frans's code? I don't think you can get right result.
I think it won't Smilie
shell code:
  1. read - p "enter place : " VALUE
  2. sed "s/place=/place=$VALUE/g" /root/user/mark.txt # for test purpose
  3. # sed -i "s/place=/place=$VALUE/g" /root/user/mark.txt # if you want to modify the file
  4. echo " place changed to $VALUE"
if you already have place=Arizona and you enter California, it will output place=CaliforniaArizona.
How does the file look like? if place=<PLACE> is alone on its line, first you don't need the g (global) option of sed substitution, second you can write
Code:
sed "s/place=.*/place=$VALUE/"

You should post a sample of your data file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in reading the input value

echo "Enter the Value : " read value sed '1s:\(.\{6\}\)\(.\{4\}\):\1'$value':' flextran$RUN_DATE-completed.txt > temp.txt mv temp.txt flextran$RUN_DATE-completed.txt on the run time after entering the input value it waits for keystroke and the values is not input to the function The output... (4 Replies)
Discussion started by: rammm
4 Replies

2. Shell Programming and Scripting

Reading from standard input

So, I am new to shell scripting and have a few problems. I know how to read from standard input but I do not know how to really compare it to say, a character. I am trying to compare it to a character and anything exceeding just a character, the user will get an output message, but the program... (7 Replies)
Discussion started by: Bungkai
7 Replies

3. Shell Programming and Scripting

Reading Standard Input

Hello, I am new to scripting. How do I read multiple lines from the command line? I know read reads one line, but if I have to read multiple lines, how should I do? Thanks, Prasanna (4 Replies)
Discussion started by: prasanna1157
4 Replies

4. Shell Programming and Scripting

Reading input files

Okay, so I've looked on here and found some similar things, but not exactly what I am looking for. I am working on creating a script that can back up some files, based on the contents of another file - the configuration file. First file contains the files to back up - we'll call this... (1 Reply)
Discussion started by: pdxwarrior
1 Replies

5. Shell Programming and Scripting

Reading specific contents from 1 input files and appending it to another input file

Hi guys, I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help. I have 2 input files (example given below) Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies

6. Shell Programming and Scripting

reading input from a file

I am trying to read input for a C program (that expects input from the user) from a file using the shell command: progname < filename but it seems that the program considers the char '<' as the first input, hence causing an "error" in my program. I checked it with another program and it... (2 Replies)
Discussion started by: nadbar
2 Replies

7. Shell Programming and Scripting

Reading an Input file and searching for occurrences WIHOUT SED or AWK

Hi people. I am new to shell scripting, so I need a little help. I want to create a script named that takes an argument as a file, Read the input file and look for occurrences of the current username (say abc.xyz) who is executing the script. On finding an occurrence of the username take that line... (2 Replies)
Discussion started by: kartikkumar84@g
2 Replies

8. Shell Programming and Scripting

Reading input from user

how do we read input from a user e.g i want to ask a user to enter 6 sets of numbers how do i control information from the user? i have this....... #!/bin/bash echo "Please enter six numbers" read number echo $number >> file1 but this stops after the first number..how can i... (2 Replies)
Discussion started by: vadharah
2 Replies

9. Shell Programming and Scripting

reading from input

Hi guys , As you know normally ' read ' statement waits for the user to press enter and then terminates the input ............. Can anyone of u tell me how do i read a single character from input without waiting for the user to press enter ................ Thanks, Nagesh. (1 Reply)
Discussion started by: nageshrc
1 Replies

10. UNIX for Dummies Questions & Answers

Reading Input in a Script

#!/usr/bin/sh echo "Enter reason:" echo "> \c" read $reason $reason >> access.log This doesnt work for me. Can someone tell me how I would read the input from what the person types, and then append that to the log file? Regards (2 Replies)
Discussion started by: alwayslearningunix
2 Replies
Login or Register to Ask a Question