Results 1 to 3 of 3
Something very handy to do in a Linux shell, is manipulating files and strings - essentially parsing data. Write a utility which will scan in a text file and search ...
- 07-16-2010 #1Just Joined!
- Join Date
- Jul 2010
- Posts
- 1
bash scripting
Something very handy to do in a Linux shell, is manipulating files and strings - essentially parsing data. Write a utility which will scan in a text file and search and replace strings. We also want to keep track of how many strings we've replaced.
I know that my command would look like this: <utility name> <filename> <stringToSearchFor> <stringToReplaceWith>
The above is the code that I have so far. As of now stringZ is nothing. I need it to be the line being read in. I also need to figure out how to write linein back into a file.Code:#!/bin/bash # code for reading in a file line by line. fileIn=$1 while read linein do echo $linein done < $fileIn ${stringZ//$2/$3}
This is for a homework assignment. I'm not looking for someone to do it for me, I know that is against the rules anyway. I'm just looking for hints.
- 07-19-2010 #2Just Joined!
- Join Date
- Jul 2010
- Location
- Adelaide, Australia
- Posts
- 3
It is all good and well to be writing a script to do this, but the program sed already does this just fine.
- 07-21-2010 #3Linux Newbie
- Join Date
- Apr 2007
- Posts
- 119
A pretty good place for bash scripting. If you run into problems with your script after you get it written, let us know and we can probably help.


Reply With Quote