LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to print lines in csv file if 1 csv column field = "text". There are 10 column (;) in csv file (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-print-lines-in-csv-file-if-1-csv-column-field-%3D-text-there-are-10-column-%3B-in-csv-file-4175578014/)

nexuslinux 04-21-2016 06:22 AM

How to print lines in csv file if 1 csv column field = "text". There are 10 column (;) in csv file
 
How to print lines in csv file if 1 csv column field = "xxxxx".

xxxxx = alphabet
xxxxx = numeric

There are 10 column in csv file:
For instant : Test result;unix timestamp;1234567890;2233;111;A;B;C;D;E

If csv column 5= 111, then print the line in source file

syg00 04-21-2016 06:58 AM

And have you made any effort to solve this yourself ?.

Habitual 04-21-2016 06:59 AM

Welcome to LQ!
How about some actual data and not some arbitrary 'examples"?

schneidz 04-21-2016 07:20 AM

i would look into the awk command.

HMW 04-21-2016 07:26 AM

Quote:

Originally Posted by Habitual (Post 5534474)
Welcome to LQ!
How about some actual data and not some arbitrary 'examples"?

^Ditto. But here are a couple of hints:
• awk
• field separator

Example:
Code:

echo "Test result;unix timestamp;1234567890;2233;111;A;B;C;D;E
> Test result;unix timestamp;1234567890;2233;112;A;B;C;D;E
> Test result;unix timestamp;1234567890;2233;113;A;B;C;D;E
> Test result;unix timestamp;1234567890;2233;114;A;B;C;D;E" | awk <hidden>
Test result;unix timestamp;1234567890;2233;111;A;B;C;D;E

Best regards,
HMW

grail 04-21-2016 07:50 AM

Another vote for awk. If you are thinking in columns, you should often be thinking awk :)

nexuslinux 04-22-2016 08:04 PM

This posting has been cancelled due to click post button unintentionally

nexuslinux 04-22-2016 08:08 PM

Quote:

Originally Posted by grail (Post 5534497)
Another vote for awk. If you are thinking in columns, you should often be thinking awk :)



Anyway, I just applied the grep CLI and manage to print the lines with specific column [2233].
Example source file:
Test result;unix timestamp;1234567890;2233;111;A;B;C;D;E
Test result;unix timestamp;1234567890;2235;111;A;B;C;D;E

grep 2233 [source filename] > output file
>Test result;unix timestamp;1234567890;2233;111;A;B;C;D;E

syg00 04-22-2016 09:01 PM

No, you printed lines that had that number anywhere in the entire record. You could do it with grep, but you'll need some regex to eliminate the unwanted columns.

grail 04-22-2016 11:35 PM

Using a mod of your example shows what syg00 is saying:
Code:

$ cat source.file
Test result;unix timestamp;1234567890;2233;111;A;B;C;D;E
Test result;unix timestamp;1223367890;2235;111;A;B;C;D;E
$ grep 2233 source.file
Test result;unix timestamp;1234567890;2233;111;A;B;C;D;E
Test result;unix timestamp;1223367890;2235;111;A;B;C;D;E

As you can see, the highlighted portions match but are not in the same columns.


All times are GMT -5. The time now is 09:21 PM.