Score:-1

match all the items that i have enough of to afford. simple regex

in flag

Taking a self guided linux tutorial and I keep getting hung up on this

My output keeps including the "clock 15" please help

#!/bin/sh
#comment single RegEx to match all of the items that you have enough rupees 
sed '1d' hw0207.txt | grep -v [2-9][0-9]
#comment grep will filter all numbers greater than 12, -v represents not
#comment first sed was to remove first line

regex to match directions

I'm trying to write a single RegEx to match all of the items that you have enough rupees for. with don’t just match the lines, you should match the lines that you can afford so that if the prices change the answer will still be correct. You only have 12 rupees, if you want to buy anything more you’ll need to be a little richer.

Input file (hw0207.txt) Expected output of script
item cost
lamp oil 5
rope 10
clock 15
bombs 20
ar flag
Which distro and version of Linux are you using? Your regex is to exclude numbers between 20 and 99. That's why 15 is not excluded.
CryptoTrader avatar
in flag
only display what is over 12 or less
CryptoTrader avatar
in flag
i want it to display only the items that are 12 or less even if the value of the item changes
CryptoTrader avatar
in flag
Ubuntu 20.04.3 LTS
Score:0
ar flag

There are many ways to do this. I will show two:

Exclude

This method uses the -v option in grep as shown in the question above. I will break it down to two sets of numbers separated by the OR condition. First set of numbers include 13 to 19. The second set of numbers are 20 to 99. If either of these conditions are satisfied they will not be selected in the output.

sed '1d' hw0207.txt | grep -v '1[3-9]\|[2-9][0-9]'

Select

This approach selects lines that has numbers less than 12. Once again we break it up into two sets of numbers. First is the single digit numbers between 1 to 9 and the second is double digit numbers between 10 and 12.

sed '1d' hw0207.txt | grep  ' [1-9]$\| 1[0-2]$'

Note the leading spaces and the $ at the end.

Alternately:

sed '1d' hw0207.txt | grep -w '[1-9]\|1[0-2]'

Hope this helps

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.