Find the answer to your Linux question:
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 ...
  1. #1
    Just 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>

    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}
    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.

    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.

  2. #2
    Just 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.

  3. #3
    Linux 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...