1

I had a question regarding the awk command. I want to take a bunch of files and find a single line from each and extract them into a comma seperated text file such that I can import it into excel for graphing purposes. It worries me however because the program I use outputs .info files and I have heard that awk only works with text files. Is grep the best option? If so how can I make it such that the output is comma seperated?

The files outputted from the program are ended with .phy.rooting.0.rearrange.0.info

The .info files contains a line that states: Duplications:2

These are where I get the information I have to remove.

This command works currently, but I was hoping for a more updated one and also possible the challenge of changing the code for learning, if that makes sense.

The code that works is:

grep -w Duplications: *.info| grep -v Conditional >dups

However, I kind of want to see If i can make an Awk code that could do the same thing.

2
  • It's reletaed absolotedly to your scenario, please explain more about work and even write a piece of code even wrong.... Commented Apr 28, 2015 at 21:33
  • I added some more detail in the post, hopefully it makes more sense.
    – Nathan
    Commented Apr 28, 2015 at 21:40

1 Answer 1

3

The awk equivalent of

grep -w Duplications: *.info| grep -v Conditional >dups

would be

awk '/\<Duplications:/ && !/Conditional/ {print}' *.info > dups

If a line matches the word "Duplications:" and the line does not contain "Conditional", print the line.

I don't think awk offers any benefits over grep here.

5
  • Thank You! Sorry for asking(new to unix), but this would create a .txt file right? How would each value be listed?
    – Nathan
    Commented Apr 28, 2015 at 22:05
  • 1
    Try it and see. Commented Apr 28, 2015 at 22:05
  • This is probably an error on my side, but when I run it it gives me an error of awk: can't open file *.info. Any ideas why that would be the response?
    – Nathan
    Commented Apr 28, 2015 at 22:20
  • have you changed directory to where your .info files are? Commented Apr 28, 2015 at 23:19
  • Yea, I ran the code within that directory. I made the code into a command file and ran it that way with permissions. Should I show the path to my directory in it? it would be in the same folder as the files. I could just do . right?
    – Nathan
    Commented Apr 29, 2015 at 0:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .