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.

4
  • When I use this for loop structure: for i in ls -d *mcp; do tail -1 "$i" | awk '{ printf "%d %s %s %s\n",NR, $8, $9, $10}' >> ${Pout}${output} done I get the following output: 1 -0.242 125.104 35.0 1 -6.308 151.717 28.1 1 13.764 144.429 130.0 1 -56.022 -27.779 109.3 1 -9.461 156.412 4.0 Instead of all ones in the first column I want 1,2,...n. Does that clear things up? Commented May 13, 2015 at 19:30
  • I understand your suggestion. However, that line in my for loop was working for me, which is why I didn't change it. Yes, it may be longer than what you wrote, but I didn't change it because it did what I needed it to do. Commented May 13, 2015 at 19:35
  • Using backtics and ls means you are using two unnecessary processes. See whether my proposals below work for you. Commented May 13, 2015 at 19:43
  • (1) Don’t parse the output of ls.  for i in `ls -d *mcp` isn’t just inefficient; it produces wrong results if filenames contain certain special characters.  (2) Don’t post multi-line commands or output in comments.  Clarifications to the question, to include things that you’ve tried, results that you’ve gotten, and results that you want, belong in the question — edit the question to put them there.  (3) When you do use command substitution, use $(…) instead of `…`.  (4) If you must display a ` in code in a comment, type \`. Commented May 14, 2015 at 9:37