خرید بک لینک

grep is a pretty common Unix/Linux command, at least I've yet to come across any distro's that I've had to specifically install the basic grep (vs. say egrep or another filter command).

take piped input, filter out certain strings and write the rest to standard output.

To use it like that to filter it out, you could do the following (assuming you're using cat to print a file to standard output)

cat "some_file.txt" | grep -v "text to omit"

Additionally, grep also works on files as well, so the above command could just be written as such:

grep -v "text to omit" "some_file.txt"

The -v flag tells grep to print everything except the specified text. If you want a case in-sensitive search you would need to specify the -i flag.

it's not one item per line, it's all items on the same line, separated by spaces not newlines.

To this, you could add a for loop to iterate over the words and still utilize grep to achieve what you're needing, example:

for word in "hello there how" are you how "am i today"; do echo $word; done | grep -v "how"

The output for this would be:

are
you
am i today

The first part of for word in is the shell scripting for loop. The link provided is specific to BASH but the syntax is pretty similar among the other shells (at least for CSH, KSH and ASH), so you might have to adjust to have the syntax match your specific shell.

Hope that can help.

برچسب: نویسنده: استخدام کار تاريخ: جمعه 6 فروردين 1395 ساعت: 12:23

صفحه بندی