Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • 1
    What does the .sh_history file contain? Do you need to run strings on it? You're also doing tail -1 on it, so there's not much to loop over, if looping over the output of that function is what you mean. Can you edit the question to contain some example of the input file contents? And please take a peek at the editing help, the part about code block formatting. Commented Dec 3, 2017 at 18:08
  • grep '^\string' looks for lines which begin with one whitespace character followed by the letters t r i n g. This regexp will never match substring AA. I cannot fully understand what is it that you are asking, but you seem to want to find the second field separated by whitespace, or the null string is no such field exists; sed -e 's/$/ /' | cut -d' ' -f2 will do the trick. (The sed appends a space character, thus making sure that cut is satisfied.) Commented Dec 3, 2017 at 23:31