Get values from the pipe separated file

MSD

I'm trying to get the 2nd and 5th column details from the pipe separated file.

5th column is getting trimmed while reading from the dummy file. i tried using the get line function also. How to get the entire 5th column in the string?

File looks like:

1|6705|SW|447|C/A-"WAR" FROM CAR COMPANY    |||RFD|E|0|
2|6706|CA|448|CAR TYPE OR CUST. ID, REQ     |||RFD|E|0|
3|6707|CZ|448|CAR TYPE OR CUST. ID, REQ     |||RFD|E|0|

The code

  std::string cmd = "awk -F'|'  '{ print $2, $5 }' 1.txt >> tmp.txt";
    system(cmd.c_str());// extract the two columns and write to dummy file
    ifstream read( "tmp.txt");
    std::string line;

    while (std::getline(read, line)) // Read the file line by line
    {
            std::istringstream iss(line);
            string a, b;
            if (!(iss >> a >> b)) { break; } // error
            std::cout<<"a"<<a<<"  b  "<<b<<std::endl;
    }
    read.close();
    system("rm tmp.txt");

The output

key(string): 6705, value(int): C/A-"WAR"
key(string): 6706, value(int): CAR
key(string): 6707, value(int): CAR

richard.g

The std::cin >>operator reads strings by blanks or newlines, so in your case, the value of C/A-"WAR" FROM CAR COMPANY will be truncated into C/A-"WAR",FROM, CAR and COMPANY. You may use getline instead.

while (std::getline(read, line)) // Read the file line by line
{
        std::istringstream iss(line);
        string a, b;
        iss>>a;
        getline(iss,b);//This may work
        std::cout<<"a"<<a<<"  b  "<<b<<std::endl;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get all values from a variable made of value separated by a pipe ( | )?

From Dev

Get values separated by pipe ("|") in C#

From Dev

Split data separated by pipe from a file perl

From Dev

Take specific columns and specific line from a pipe separated file

From Dev

Multiple values separated by a pipe in Java

From Dev

Remove values from NUL separated file

From Dev

Get unique values from a comma separated values in a cell

From Dev

Get values from a column having comma separated values using Linq

From Dev

How to use sed to modify the value in a specific column in a file with pipe-separated values

From Dev

Pipe separated values in groups of 3 regex

From Dev

Create JSON using jq from pipe-separated keys and values in bash

From Dev

Reading PSV (pipe-separated) file or string

From Dev

How to retrieve individual values, which are not separated by a delimiter, from a .csv file?

From Dev

Read comma separated values from a text file using php

From Dev

Linux Shell: Extract values separated by pipes from a file

From Dev

Hive - insert values in array from file (comma and semicolon separated)

From Dev

Putting values from file separated by space into multi dimension array

From Dev

How can I use awk (or cut) to print the last field per line from a pipe separated file?

From Dev

How do I get multiple comma separated values from URL

From Dev

Get values from the key-value pairs in a comma separated string

From Dev

Get specific values from comma separated string in mysql

From Dev

KnockoutJS custom binding to get comma separated values from multi select

From Dev

Get all file paths from a certain point and pipe to text file

From Dev

PHP get data from text file (line and multispacing separated)

From Dev

Perl script to remove line from one pipe-separated file using another file have one matching column

From Dev

Get argument from pipe

From Dev

Easier way to convert pipe separated string into variables and values?

From Dev

How to parse pipe-separated Attribute=Values pairs?

From Dev

Calculating maximum using existence in pipe separated column values in MySQL

Related Related

  1. 1

    How to get all values from a variable made of value separated by a pipe ( | )?

  2. 2

    Get values separated by pipe ("|") in C#

  3. 3

    Split data separated by pipe from a file perl

  4. 4

    Take specific columns and specific line from a pipe separated file

  5. 5

    Multiple values separated by a pipe in Java

  6. 6

    Remove values from NUL separated file

  7. 7

    Get unique values from a comma separated values in a cell

  8. 8

    Get values from a column having comma separated values using Linq

  9. 9

    How to use sed to modify the value in a specific column in a file with pipe-separated values

  10. 10

    Pipe separated values in groups of 3 regex

  11. 11

    Create JSON using jq from pipe-separated keys and values in bash

  12. 12

    Reading PSV (pipe-separated) file or string

  13. 13

    How to retrieve individual values, which are not separated by a delimiter, from a .csv file?

  14. 14

    Read comma separated values from a text file using php

  15. 15

    Linux Shell: Extract values separated by pipes from a file

  16. 16

    Hive - insert values in array from file (comma and semicolon separated)

  17. 17

    Putting values from file separated by space into multi dimension array

  18. 18

    How can I use awk (or cut) to print the last field per line from a pipe separated file?

  19. 19

    How do I get multiple comma separated values from URL

  20. 20

    Get values from the key-value pairs in a comma separated string

  21. 21

    Get specific values from comma separated string in mysql

  22. 22

    KnockoutJS custom binding to get comma separated values from multi select

  23. 23

    Get all file paths from a certain point and pipe to text file

  24. 24

    PHP get data from text file (line and multispacing separated)

  25. 25

    Perl script to remove line from one pipe-separated file using another file have one matching column

  26. 26

    Get argument from pipe

  27. 27

    Easier way to convert pipe separated string into variables and values?

  28. 28

    How to parse pipe-separated Attribute=Values pairs?

  29. 29

    Calculating maximum using existence in pipe separated column values in MySQL

HotTag

Archive