1

Here are some values I have in a file named "example"--I only put one row but there are about a thousand.

a  7  q  y  4  5  8  9  5  6  567  5678578  56784  345  345  2  df  4  1  245
b  7  q  y  4  5  8  9  5  6  567  5674578  56789  334  324  3  df  4  1  245

Specifically, see in column 1 how the values are a or b? That goes on for the rest of the thousand rows, where column one will either be a or b. I want to separate the rows so that all rows with the value "a" are in one file, and all rows with value "b" are in another file. Is that possible?

awk '$1 == a' /home/me/example > /home/me/rowa

I've tried that to no success, but I don't know why. Can anyone help clarify?

  • 3
    Please edit your question and remove the annoying all caps title and include sample input data. – jasonwryan Jul 17 '17 at 22:02
  • 2
    We can't help you if you don't show us an example of your file and don't tell us how what you tried failed. That command should have worked, so something is different in your data. So please edit your question and add an extract of your file. – terdon Jul 17 '17 at 22:18
  • Please give us an example of the data, and tell us what separates the columns (it might not be obvious if it's spaces or tabs). – Bob Eager Jul 17 '17 at 22:27
0

easy with awk command

awk '{print > $1".txt"}' infile.txt

this will produce two files "a.txt" containing those lines which column one is only "a" and "b.txt" containing those lines which column one is only "b" if your column one only contains a or b

the above is when your data delimited by tab or space, in case it's different than these we could tell it to awk with its -F"DELIMITER", which DELIMITER represents your file feilds delimiter.

  • I'm not printing the entire column one though, I want the rows with value "a" to be in one file and the rows with value "b" in another file. – voldemort Jul 19 '17 at 15:43
  • yes, it will separate As lines in a.txt and Bs lines in b.txt – αғsнιη Jul 19 '17 at 15:45
  • your welcome, please don't forgot to mark the answer as accepted, a thick mark next to the answer : ) – αғsнιη Jul 19 '17 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.