pipeline delimiter and some fields having comma those should be placed in double quotes and it supposed to be taken as single filed [closed]

Clash Royale CLAN TAG#URR8PPP
i Have one csv file.
input.
India|Andhra|asd,ged,ijn|telangana|41657|hgjd,dfef,edf|dfd
output
India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd
awk csv
closed as unclear what you're asking by Jeff Schaller♦, jimmij, Michael Homer, DarkHeart, roaima Mar 7 at 11:50
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
|
show 1 more comment
i Have one csv file.
input.
India|Andhra|asd,ged,ijn|telangana|41657|hgjd,dfef,edf|dfd
output
India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd
awk csv
closed as unclear what you're asking by Jeff Schaller♦, jimmij, Michael Homer, DarkHeart, roaima Mar 7 at 11:50
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
What have you tried so far? How did that attempt deviate from your expectations?
– Fox
Mar 6 at 13:27
2
There are plenty of characters available in the body of your Question to describe the question. Do not feel like you need to fit it all into the title, please & thank you!
– Jeff Schaller♦
Mar 6 at 13:34
awk ']+/,""&"")1' i tried this but it is replacing whole data
– Aswani
Mar 6 at 13:45
awk ']+/,""&"")1' i tried this but it is replacing whole data Input: India|Andhra|asd,ged,ijn|telangana|41657|hgjd,dfef,edf|dfd apple|grape|orange|strawberry|12543|mango output: India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd apple,grape,orange,strawberry,12543,mango or India|Andhra|"asd,ged,ijn"|telangana|41657|"hgjd,dfef,edf|dfd" apple|grape|orange|strawberry|12543|mango
– Aswani
Mar 6 at 13:54
awk -F| -vOFS=, 'for(i=1;i<=NF;i++)if($i~OFS)$i="""$i"""; print'; but as the other have said, use a csv tool, that knows how to deal with csv's format pitfalls.
– mosvy
Mar 6 at 18:59
|
show 1 more comment
i Have one csv file.
input.
India|Andhra|asd,ged,ijn|telangana|41657|hgjd,dfef,edf|dfd
output
India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd
awk csv
i Have one csv file.
input.
India|Andhra|asd,ged,ijn|telangana|41657|hgjd,dfef,edf|dfd
output
India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd
awk csv
awk csv
edited Mar 6 at 13:35
Kusalananda♦
139k17259432
139k17259432
asked Mar 6 at 13:24
AswaniAswani
41
41
closed as unclear what you're asking by Jeff Schaller♦, jimmij, Michael Homer, DarkHeart, roaima Mar 7 at 11:50
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Jeff Schaller♦, jimmij, Michael Homer, DarkHeart, roaima Mar 7 at 11:50
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
What have you tried so far? How did that attempt deviate from your expectations?
– Fox
Mar 6 at 13:27
2
There are plenty of characters available in the body of your Question to describe the question. Do not feel like you need to fit it all into the title, please & thank you!
– Jeff Schaller♦
Mar 6 at 13:34
awk ']+/,""&"")1' i tried this but it is replacing whole data
– Aswani
Mar 6 at 13:45
awk ']+/,""&"")1' i tried this but it is replacing whole data Input: India|Andhra|asd,ged,ijn|telangana|41657|hgjd,dfef,edf|dfd apple|grape|orange|strawberry|12543|mango output: India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd apple,grape,orange,strawberry,12543,mango or India|Andhra|"asd,ged,ijn"|telangana|41657|"hgjd,dfef,edf|dfd" apple|grape|orange|strawberry|12543|mango
– Aswani
Mar 6 at 13:54
awk -F| -vOFS=, 'for(i=1;i<=NF;i++)if($i~OFS)$i="""$i"""; print'; but as the other have said, use a csv tool, that knows how to deal with csv's format pitfalls.
– mosvy
Mar 6 at 18:59
|
show 1 more comment
1
What have you tried so far? How did that attempt deviate from your expectations?
– Fox
Mar 6 at 13:27
2
There are plenty of characters available in the body of your Question to describe the question. Do not feel like you need to fit it all into the title, please & thank you!
– Jeff Schaller♦
Mar 6 at 13:34
awk ']+/,""&"")1' i tried this but it is replacing whole data
– Aswani
Mar 6 at 13:45
awk ']+/,""&"")1' i tried this but it is replacing whole data Input: India|Andhra|asd,ged,ijn|telangana|41657|hgjd,dfef,edf|dfd apple|grape|orange|strawberry|12543|mango output: India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd apple,grape,orange,strawberry,12543,mango or India|Andhra|"asd,ged,ijn"|telangana|41657|"hgjd,dfef,edf|dfd" apple|grape|orange|strawberry|12543|mango
– Aswani
Mar 6 at 13:54
awk -F| -vOFS=, 'for(i=1;i<=NF;i++)if($i~OFS)$i="""$i"""; print'; but as the other have said, use a csv tool, that knows how to deal with csv's format pitfalls.
– mosvy
Mar 6 at 18:59
1
1
What have you tried so far? How did that attempt deviate from your expectations?
– Fox
Mar 6 at 13:27
What have you tried so far? How did that attempt deviate from your expectations?
– Fox
Mar 6 at 13:27
2
2
There are plenty of characters available in the body of your Question to describe the question. Do not feel like you need to fit it all into the title, please & thank you!
– Jeff Schaller♦
Mar 6 at 13:34
There are plenty of characters available in the body of your Question to describe the question. Do not feel like you need to fit it all into the title, please & thank you!
– Jeff Schaller♦
Mar 6 at 13:34
awk ']+/,""&"")1' i tried this but it is replacing whole data
– Aswani
Mar 6 at 13:45
awk ']+/,""&"")1' i tried this but it is replacing whole data
– Aswani
Mar 6 at 13:45
awk ']+/,""&"")1' i tried this but it is replacing whole data Input: India|Andhra|asd,ged,ijn|telangana|41657|hgjd,dfef,edf|dfd apple|grape|orange|strawberry|12543|mango output: India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd apple,grape,orange,strawberry,12543,mango or India|Andhra|"asd,ged,ijn"|telangana|41657|"hgjd,dfef,edf|dfd" apple|grape|orange|strawberry|12543|mango
– Aswani
Mar 6 at 13:54
awk ']+/,""&"")1' i tried this but it is replacing whole data Input: India|Andhra|asd,ged,ijn|telangana|41657|hgjd,dfef,edf|dfd apple|grape|orange|strawberry|12543|mango output: India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd apple,grape,orange,strawberry,12543,mango or India|Andhra|"asd,ged,ijn"|telangana|41657|"hgjd,dfef,edf|dfd" apple|grape|orange|strawberry|12543|mango
– Aswani
Mar 6 at 13:54
awk -F| -vOFS=, 'for(i=1;i<=NF;i++)if($i~OFS)$i="""$i"""; print'; but as the other have said, use a csv tool, that knows how to deal with csv's format pitfalls.– mosvy
Mar 6 at 18:59
awk -F| -vOFS=, 'for(i=1;i<=NF;i++)if($i~OFS)$i="""$i"""; print'; but as the other have said, use a csv tool, that knows how to deal with csv's format pitfalls.– mosvy
Mar 6 at 18:59
|
show 1 more comment
2 Answers
2
active
oldest
votes
Using csvformat from csvkit:
$ csvformat -d '|' file.csv
India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd
The tools in the csvkit toolbox are CSV-aware (they are all CSV parsers for modifying and querying and generally working with CSV files on the command line).
Here, I use csvformat to reformat the input file and I specify that the field delimiter in the input is a pipe symbol by using -d '|'. The output will by default use commas as field delimiters, and the tool will escape and quote things as necessary.
awk ']+/,""&"")1' I tried this but it is replacing whole data. I tried with csvformat -d '|' file.csv I'm getting error as -ksh: csvformat: not found [No such file or directory]
– Aswani
Mar 6 at 13:45
@Aswanicsvformatis seldom installed by default. You would have to install csvkit manually. This could be done withpip install --user csvkitand then adding~/.local/binto your path.
– Kusalananda♦
Mar 6 at 13:50
its a shared server so we dont have rights to install
– Aswani
Mar 6 at 14:00
@Aswani The command I mentioned would install in your home directory.
– Kusalananda♦
Mar 6 at 14:07
when I'm trying to install its prompting error as -ksh: pip: not found [No such file or directory]
– Aswani
Mar 6 at 14:12
|
show 1 more comment
If you have ruby installed:
ruby -rcsv -e '
rdr = CSV.new(File.new(ARGV.shift), col_sep: "|")
wtr = CSV.new($stdout)
rdr.each row
' file.csv
India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd
No ruby installed in my server:(
– Aswani
Mar 6 at 14:52
I'm using putty and im writing unix shell script for file formatting
– Aswani
Mar 6 at 14:57
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Using csvformat from csvkit:
$ csvformat -d '|' file.csv
India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd
The tools in the csvkit toolbox are CSV-aware (they are all CSV parsers for modifying and querying and generally working with CSV files on the command line).
Here, I use csvformat to reformat the input file and I specify that the field delimiter in the input is a pipe symbol by using -d '|'. The output will by default use commas as field delimiters, and the tool will escape and quote things as necessary.
awk ']+/,""&"")1' I tried this but it is replacing whole data. I tried with csvformat -d '|' file.csv I'm getting error as -ksh: csvformat: not found [No such file or directory]
– Aswani
Mar 6 at 13:45
@Aswanicsvformatis seldom installed by default. You would have to install csvkit manually. This could be done withpip install --user csvkitand then adding~/.local/binto your path.
– Kusalananda♦
Mar 6 at 13:50
its a shared server so we dont have rights to install
– Aswani
Mar 6 at 14:00
@Aswani The command I mentioned would install in your home directory.
– Kusalananda♦
Mar 6 at 14:07
when I'm trying to install its prompting error as -ksh: pip: not found [No such file or directory]
– Aswani
Mar 6 at 14:12
|
show 1 more comment
Using csvformat from csvkit:
$ csvformat -d '|' file.csv
India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd
The tools in the csvkit toolbox are CSV-aware (they are all CSV parsers for modifying and querying and generally working with CSV files on the command line).
Here, I use csvformat to reformat the input file and I specify that the field delimiter in the input is a pipe symbol by using -d '|'. The output will by default use commas as field delimiters, and the tool will escape and quote things as necessary.
awk ']+/,""&"")1' I tried this but it is replacing whole data. I tried with csvformat -d '|' file.csv I'm getting error as -ksh: csvformat: not found [No such file or directory]
– Aswani
Mar 6 at 13:45
@Aswanicsvformatis seldom installed by default. You would have to install csvkit manually. This could be done withpip install --user csvkitand then adding~/.local/binto your path.
– Kusalananda♦
Mar 6 at 13:50
its a shared server so we dont have rights to install
– Aswani
Mar 6 at 14:00
@Aswani The command I mentioned would install in your home directory.
– Kusalananda♦
Mar 6 at 14:07
when I'm trying to install its prompting error as -ksh: pip: not found [No such file or directory]
– Aswani
Mar 6 at 14:12
|
show 1 more comment
Using csvformat from csvkit:
$ csvformat -d '|' file.csv
India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd
The tools in the csvkit toolbox are CSV-aware (they are all CSV parsers for modifying and querying and generally working with CSV files on the command line).
Here, I use csvformat to reformat the input file and I specify that the field delimiter in the input is a pipe symbol by using -d '|'. The output will by default use commas as field delimiters, and the tool will escape and quote things as necessary.
Using csvformat from csvkit:
$ csvformat -d '|' file.csv
India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd
The tools in the csvkit toolbox are CSV-aware (they are all CSV parsers for modifying and querying and generally working with CSV files on the command line).
Here, I use csvformat to reformat the input file and I specify that the field delimiter in the input is a pipe symbol by using -d '|'. The output will by default use commas as field delimiters, and the tool will escape and quote things as necessary.
answered Mar 6 at 13:34
Kusalananda♦Kusalananda
139k17259432
139k17259432
awk ']+/,""&"")1' I tried this but it is replacing whole data. I tried with csvformat -d '|' file.csv I'm getting error as -ksh: csvformat: not found [No such file or directory]
– Aswani
Mar 6 at 13:45
@Aswanicsvformatis seldom installed by default. You would have to install csvkit manually. This could be done withpip install --user csvkitand then adding~/.local/binto your path.
– Kusalananda♦
Mar 6 at 13:50
its a shared server so we dont have rights to install
– Aswani
Mar 6 at 14:00
@Aswani The command I mentioned would install in your home directory.
– Kusalananda♦
Mar 6 at 14:07
when I'm trying to install its prompting error as -ksh: pip: not found [No such file or directory]
– Aswani
Mar 6 at 14:12
|
show 1 more comment
awk ']+/,""&"")1' I tried this but it is replacing whole data. I tried with csvformat -d '|' file.csv I'm getting error as -ksh: csvformat: not found [No such file or directory]
– Aswani
Mar 6 at 13:45
@Aswanicsvformatis seldom installed by default. You would have to install csvkit manually. This could be done withpip install --user csvkitand then adding~/.local/binto your path.
– Kusalananda♦
Mar 6 at 13:50
its a shared server so we dont have rights to install
– Aswani
Mar 6 at 14:00
@Aswani The command I mentioned would install in your home directory.
– Kusalananda♦
Mar 6 at 14:07
when I'm trying to install its prompting error as -ksh: pip: not found [No such file or directory]
– Aswani
Mar 6 at 14:12
awk ']+/,""&"")1' I tried this but it is replacing whole data. I tried with csvformat -d '|' file.csv I'm getting error as -ksh: csvformat: not found [No such file or directory]
– Aswani
Mar 6 at 13:45
awk ']+/,""&"")1' I tried this but it is replacing whole data. I tried with csvformat -d '|' file.csv I'm getting error as -ksh: csvformat: not found [No such file or directory]
– Aswani
Mar 6 at 13:45
@Aswani
csvformat is seldom installed by default. You would have to install csvkit manually. This could be done with pip install --user csvkit and then adding ~/.local/bin to your path.– Kusalananda♦
Mar 6 at 13:50
@Aswani
csvformat is seldom installed by default. You would have to install csvkit manually. This could be done with pip install --user csvkit and then adding ~/.local/bin to your path.– Kusalananda♦
Mar 6 at 13:50
its a shared server so we dont have rights to install
– Aswani
Mar 6 at 14:00
its a shared server so we dont have rights to install
– Aswani
Mar 6 at 14:00
@Aswani The command I mentioned would install in your home directory.
– Kusalananda♦
Mar 6 at 14:07
@Aswani The command I mentioned would install in your home directory.
– Kusalananda♦
Mar 6 at 14:07
when I'm trying to install its prompting error as -ksh: pip: not found [No such file or directory]
– Aswani
Mar 6 at 14:12
when I'm trying to install its prompting error as -ksh: pip: not found [No such file or directory]
– Aswani
Mar 6 at 14:12
|
show 1 more comment
If you have ruby installed:
ruby -rcsv -e '
rdr = CSV.new(File.new(ARGV.shift), col_sep: "|")
wtr = CSV.new($stdout)
rdr.each row
' file.csv
India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd
No ruby installed in my server:(
– Aswani
Mar 6 at 14:52
I'm using putty and im writing unix shell script for file formatting
– Aswani
Mar 6 at 14:57
add a comment |
If you have ruby installed:
ruby -rcsv -e '
rdr = CSV.new(File.new(ARGV.shift), col_sep: "|")
wtr = CSV.new($stdout)
rdr.each row
' file.csv
India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd
No ruby installed in my server:(
– Aswani
Mar 6 at 14:52
I'm using putty and im writing unix shell script for file formatting
– Aswani
Mar 6 at 14:57
add a comment |
If you have ruby installed:
ruby -rcsv -e '
rdr = CSV.new(File.new(ARGV.shift), col_sep: "|")
wtr = CSV.new($stdout)
rdr.each row
' file.csv
India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd
If you have ruby installed:
ruby -rcsv -e '
rdr = CSV.new(File.new(ARGV.shift), col_sep: "|")
wtr = CSV.new($stdout)
rdr.each row
' file.csv
India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd
answered Mar 6 at 14:38
glenn jackmanglenn jackman
53k573114
53k573114
No ruby installed in my server:(
– Aswani
Mar 6 at 14:52
I'm using putty and im writing unix shell script for file formatting
– Aswani
Mar 6 at 14:57
add a comment |
No ruby installed in my server:(
– Aswani
Mar 6 at 14:52
I'm using putty and im writing unix shell script for file formatting
– Aswani
Mar 6 at 14:57
No ruby installed in my server:(
– Aswani
Mar 6 at 14:52
No ruby installed in my server:(
– Aswani
Mar 6 at 14:52
I'm using putty and im writing unix shell script for file formatting
– Aswani
Mar 6 at 14:57
I'm using putty and im writing unix shell script for file formatting
– Aswani
Mar 6 at 14:57
add a comment |
1
What have you tried so far? How did that attempt deviate from your expectations?
– Fox
Mar 6 at 13:27
2
There are plenty of characters available in the body of your Question to describe the question. Do not feel like you need to fit it all into the title, please & thank you!
– Jeff Schaller♦
Mar 6 at 13:34
awk ']+/,""&"")1' i tried this but it is replacing whole data
– Aswani
Mar 6 at 13:45
awk ']+/,""&"")1' i tried this but it is replacing whole data Input: India|Andhra|asd,ged,ijn|telangana|41657|hgjd,dfef,edf|dfd apple|grape|orange|strawberry|12543|mango output: India,Andhra,"asd,ged,ijn",telangana,41657,"hgjd,dfef,edf",dfd apple,grape,orange,strawberry,12543,mango or India|Andhra|"asd,ged,ijn"|telangana|41657|"hgjd,dfef,edf|dfd" apple|grape|orange|strawberry|12543|mango
– Aswani
Mar 6 at 13:54
awk -F| -vOFS=, 'for(i=1;i<=NF;i++)if($i~OFS)$i="""$i"""; print'; but as the other have said, use a csv tool, that knows how to deal with csv's format pitfalls.– mosvy
Mar 6 at 18:59