-1

This one works:

temp=($(awk -F" "  '$2 == 84' "$1".db))

This one does not (fieldnumber stores the column i wish to search, and val stores the value I'm searching for):

temp=($(awk -F" " -v column="$""$field_number" -v val="$3" '{ if(column == val) print $0;}' "$1".db))

I am trying to manipulate the awk command based on command line inputs within shell script: ./dr.sh cop4342 exam1 84 (84 is the value to be searched for) (exam1 is used within the shell script to find the column number)

code image code output

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 1
    Welcome to SO, thanks for sharing your efforts; could you please also post samples of input and expected output in your question for more clarity, thank you. – RavinderSingh13 Feb 07 '22 at 10:56
  • 2
    Please [don’t post images of code, error messages, or other textual data.](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors) – tripleee Feb 07 '22 at 10:57

1 Answers1

0

This is terribly unclear, but I guess you are looking for

temp=($(awk -F " " -v column="$field_number" \
            -v val="$3" '{ if($column == val) print $0;}' "$1".db))

which of course can be simplified to just

temp=($(awk -v column="$field_number" \
            -v val="$3" '$column == val' "$1".db))
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • yea sorry about it being unclear its like a 3 part script which uses one script to store the databases schemas in a database.txt file, another script to create each database and add to it, and a final script (this one) which needs to delete all rows that have the input value within the input column. I believe your solution works though, althought is there a way I can store all the values of the line in one array index instead of it being like this? http://prntscr.com/26q3sfy (screenshot of the printed array) I'd like each line to be in one index of the array so there would be two indexes print – Dylan Cody Feb 07 '22 at 11:12
  • Is there a reason you don't simply delete them as you find them? Probably (accept this answer, or post one of your own and accept that if you like, and) ask a new question with your _actual_ requirements if you can't figure it out. – tripleee Feb 07 '22 at 11:17
  • Sorry, I forgot to accept it, I am new to SO. Now that you mention it though, deleting when finding would definitely be optimal. I am not sure how to do that though? The file I need to delete from is the "$1.db" file. I need to delete the rows that the awk command comes back with. – Dylan Cody Feb 07 '22 at 11:21
  • Again, without more details, the answer is something like "probably". Vaguely tangentially perhaps look at https://stackoverflow.com/questions/65538947/counting-lines-or-enumerating-line-numbers-so-i-can-loop-over-them-why-is-this – tripleee Feb 07 '22 at 11:22
  • 1
    And again, please avoid screen shots of text. – tripleee Feb 07 '22 at 11:25