Complete NOOB need help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gham
    New Member
    • Jun 2007
    • 1

    Complete NOOB need help

    I am a complete noob to linux and shell scripting please help

    this is what I am trying to do
    1. Create a script that takes 1 argument being a file, read the inputted file, and look for occurrences of the current user who is executing the script. On finding an occurrence of the username take that line and append it to a file and display a line number and a bracket against the saved line

    efforts sofar

    Code:
    #!/bin/bash
    echo "filename"
    read myvar
    grep $USER $myvar > results.txt
    nl results.txt

    2. Write a script that takes two arguments. The first being a line of text, the second being a file. The script should take the first argument and insert it into the middle (the middle line) of the file named in second argument.


    thanks in advancefor any help
  • shahjapan
    New Member
    • Apr 2007
    • 63

    #2
    Originally posted by gham
    I am a complete noob to linux and shell scripting please help

    this is what I am trying to do
    1. Create a script that takes 1 argument being a file, read the inputted file, and look for occurrences of the current user who is executing the script. On finding an occurrence of the username take that line and append it to a file and display a line number and a bracket against the saved line

    efforts sofar

    Code:
    #!/bin/bash
    echo "filename"
    read myvar
    grep $USER $myvar > results.txt
    nl results.txt

    2. Write a script that takes two arguments. The first being a line of text, the second being a file. The script should take the first argument and insert it into the middle (the middle line) of the file named in second argument.


    thanks in advancefor any help
    A scratch code might be
    Code:
    #!/bin/sh
    
    cat $1 | grep $USER >> files.txt
    cat files.txt | grep $USER

    Comment

    • ghostdog74
      Recognized Expert Contributor
      • Apr 2006
      • 511

      #3
      Originally posted by shahjapan
      A scratch code might be
      Code:
      #!/bin/sh
      
      cat $1 | grep $USER >> files.txt
      cat files.txt | grep $USER
      don't teach a noob the "wrong" things. both the above cats are useless. grep takes in a file as input.
      Code:
      grep $USER $1 >> files.txt
      grep $USER files.txt

      Comment

      • ghostdog74
        Recognized Expert Contributor
        • Apr 2006
        • 511

        #4
        Originally posted by gham
        I am a complete noob to linux and shell scripting please help

        this is what I am trying to do
        1. Create a script that takes 1 argument being a file, read the inputted file, and look for occurrences of the current user who is executing the script. On finding an occurrence of the username take that line and append it to a file and display a line number and a bracket against the saved line

        efforts sofar

        Code:
        #!/bin/bash
        echo "filename"
        read myvar
        grep $USER $myvar > results.txt
        nl results.txt

        2. Write a script that takes two arguments. The first being a line of text, the second being a file. The script should take the first argument and insert it into the middle (the middle line) of the file named in second argument.


        thanks in advancefor any help
        you are doing homework right. so what's wrong with your first question? what have you done so far with your second question?

        Comment

        Working...