sh to grep and replace text files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sh to grep and replace text files
# 1  
Old 10-08-2009
Bug sh to grep and replace text files

Hello I was wondering what is a way you can put in your code that acts like goto for bash in windows ?

lets say i have a if yes or no question how would i go about doing that?

Also how can i search for text inside a file and insert my text into that part if you dont mind me asking?
# 2  
Old 10-08-2009
If you need a GOTO, you did something wrong, or chose the wrong language. Windows batch programs require the use of GOTO because it lacks constructs like blocks, loops, functions, and case/switch decisions. The simplest case for your example would be:
Code:
read yesno
case ${yesno} in
    [Yy] ) echo "Yes" ;;
    [Nn] ) echo "No" ;;
    * ) echo "Other" ;;
esac

For loops (for/while/until) there's break and continue.
# 3  
Old 10-08-2009
Ok so if user types in yes what i would do after that for example if yes then goto other place if no then goto another place how would that be implemented? and thankyou pludi


like this?

Code:
for [Yy] then  do balhbalhblahb  

for  [Nn] then do blalalslsls

# 4  
Old 10-08-2009
Code:
case ${yesno} in
  [Yy])
    do balhbalhblahb
  ;;
  [Nn])
    do blalalslsls
  ;;
esac

# 5  
Old 10-08-2009
When i use something like

Code:
read yesno
case ${yesno} in
    [Yy] ) echo "Yes" ;;
    [Nn] ) echo "No" ;;
    * ) echo "Other" ;;
esac

case ${yesno} in
  [Yy])
    do echo "hi"
  ;;
  [Nn])
    do echo " test"
  ;;
esac

it just acts as if its executing and does nothing ?
# 6  
Old 10-08-2009
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and replace using 2 text files as arrays.

Here's the nonfunctional code I have so far #!/bin/bash searchFor=(`cat filea.txt` ) replaceWith=(`cat fileb.txt`) myMax=${#searchFor} myCounter=1 while ; do sed -i 's/${$searchFor}/${$replaceWith}/g' done The goal is to use each line in filea.txt as a search term, and each line... (2 Replies)
Discussion started by: Erulisseuiin
2 Replies

2. Shell Programming and Scripting

Search and replace text in many files

Hello, I am very new to Linux and am trying to find a way for following problem. I have a number of files in a folder as Export000.dat, Export001.dat ..and so on. Each file has a string field 'Absolute velocity'. I want it to be replaced by 'Pixel shift' in all the files. I tried something like... (4 Replies)
Discussion started by: chirag.joshi
4 Replies

3. Shell Programming and Scripting

Find and add/replace text in text files

Hi. I would like to have experts help on below action. I have text files in which page nubmers exists in form like PAGE : 1 PAGE : 2 PAGE : 3 and so on there is other text too. I would like to know is it possible to check the last occurance of Page... (6 Replies)
Discussion started by: lodhi1978
6 Replies

4. Shell Programming and Scripting

Replace text in SPECIFIC multiple files

I have a list of files with different file names and ext that i need replace(saved as file_list.txt.) i just want to replace from a specific file list. i obtain an error saying lint not found. Plz help. Thx perl -e "s/$NAME/$T_NAME/gi;" -pi $(find . -type f | xargs -0 lint -e < file_list.txt) (0 Replies)
Discussion started by: yvmy
0 Replies

5. UNIX for Dummies Questions & Answers

replace text in multiple files

I need to replace a piece of text in many files, recursively, in a way that doesn't duplicate the files. How would I do that? The closest I've come is grep -rl "text" * | sed -e 's/home1/home2/g' but that just replaces the filename. (2 Replies)
Discussion started by: dhinge
2 Replies

6. Shell Programming and Scripting

grep command to replace multiline text from httpd.conf file on Fedora

Hi, I am a newbie to shell scripting and to Linux environment as well. In my project I am trying to search for following text from the httpd.conf file <Directory '/somedir/someinnerdir'> AllowOverride All </Directory> and then remove this text and again rewrite the same text. The... (1 Reply)
Discussion started by: bhushan
1 Replies

7. Shell Programming and Scripting

Replace text in multiple files

Dear all My task is to replace a strings in multiple files. filename: file1 I can use sed to replace abc.server.com to unix.server.org e.g. sed 's/abc.server.com/unix.server.org/g file1 > newfile1 I have 2 questions. How do I directly save file1 instead of append to newfile1. I... (1 Reply)
Discussion started by: on9west
1 Replies

8. Shell Programming and Scripting

Replace text in multiple files

Ok guys, If anyone could help me out on this puppy I'd be very appreciative! Here's the scenario I have a string for example : <img src=BLANK_IMG border=0 width=221 height=12> or <img src=IMG border=0 height=12 width=221 > or anything else really.... need to basically change each... (10 Replies)
Discussion started by: Tonka52
10 Replies

9. UNIX for Dummies Questions & Answers

Replace text in match files

Hi all, I want to replace text 'DEF' for those files containing text 'ABC'. I can only locate the files containing text 'ABC', but I don't know how to replace the text 'ABC' with 'DEF'. I use the following command to locate the files containing 'ABC' find . -exec grep -l 'ABC'... (1 Reply)
Discussion started by: wilsonchan1000
1 Replies

10. UNIX for Dummies Questions & Answers

grep multiple text files in folder into 1 text file?

How do I use the grep command to take mutiple text files in a folder and make one huge text file out of them. I'm using Mac OS X and can not find a text tool that does it so I figured I'd resort to the BSD Unix CLI for a solution... there are 5,300 files that I want to write to one huge file so... (7 Replies)
Discussion started by: coppertone
7 Replies
Login or Register to Ask a Question