convert a text file to csv using shell script

Kiran Reddy

I am new to shell scripting, can anyone give me shell script for the condition below

My Input:

id | name | values
----+------+--------
  1 |  abc |      2
  1 |  abc |      3
  1 |  abc |      4
  1 |  abc |      5
  1 |  abc |      6
  1 |  abc |      7

Expected Output:

1,abc,2
"
"
1 million records
anubhava

You can use awk for this:

awk -F '[[:blank:]]*\\|[[:blank:]]*' -v OFS=, 'NF==3 && NR>1{sub(/^[[:blank:]]*/, "", $1); print}' file
1,abc,2
1,abc,3
1,abc,4
1,abc,5
1,abc,6
1,abc,7

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 convert xlsx file to csv file using shell script?

From Dev

using shell script to format text file content

From Dev

Using shell script to extract text file to a variable

From Dev

How to convert a CSV file using a PHP script

From Dev

How to convert a CSV file using a PHP script

From Dev

How to convert a text file to CSV using Bash

From Dev

How to convert a text file to CSV using Bash

From Dev

Convert text file to avro using Pig script

From Dev

Create a CSV file from a specific log file using shell script

From Dev

Inserting text at begining of each line of text file using shell script

From Dev

Convert a Column oriented file to CSV output using shell

From Dev

Parsing key value in an csv file using shell script

From Dev

Bulk Copy from a csv file to OracleDB using shell script

From Java

Get specific line from text file using just shell script

From Dev

Replace a string in a text file using a shell script not working properly

From Dev

Finding duplicate blocks of text within a file using shell script

From Dev

single text file on require multiple operations using a shell or bash script

From Dev

How to convert a CSV file into a JSON script using Node.js?

From Dev

parse a text file in shell script

From Dev

I need a shell script to convert a csv file into pipe (|) delimited file by keeping the commas inside the enclosing quotes

From Dev

Python script for reformatting a text file into a csv using Python

From Dev

Text to speech using shell script

From Dev

How to convert this text file to csv?

From Dev

renaming file using shell script

From Dev

Batch file for loop convert to shell script

From Dev

Convert batch file for loop to shell script for loop

From Dev

Shell script to convert the date format in a file

From Dev

Shell script to validate a csv file column by column

From Dev

I need to copy the contents of a text file just before the first occurance of a specified word in shell script using shell script.

Related Related

  1. 1

    How to convert xlsx file to csv file using shell script?

  2. 2

    using shell script to format text file content

  3. 3

    Using shell script to extract text file to a variable

  4. 4

    How to convert a CSV file using a PHP script

  5. 5

    How to convert a CSV file using a PHP script

  6. 6

    How to convert a text file to CSV using Bash

  7. 7

    How to convert a text file to CSV using Bash

  8. 8

    Convert text file to avro using Pig script

  9. 9

    Create a CSV file from a specific log file using shell script

  10. 10

    Inserting text at begining of each line of text file using shell script

  11. 11

    Convert a Column oriented file to CSV output using shell

  12. 12

    Parsing key value in an csv file using shell script

  13. 13

    Bulk Copy from a csv file to OracleDB using shell script

  14. 14

    Get specific line from text file using just shell script

  15. 15

    Replace a string in a text file using a shell script not working properly

  16. 16

    Finding duplicate blocks of text within a file using shell script

  17. 17

    single text file on require multiple operations using a shell or bash script

  18. 18

    How to convert a CSV file into a JSON script using Node.js?

  19. 19

    parse a text file in shell script

  20. 20

    I need a shell script to convert a csv file into pipe (|) delimited file by keeping the commas inside the enclosing quotes

  21. 21

    Python script for reformatting a text file into a csv using Python

  22. 22

    Text to speech using shell script

  23. 23

    How to convert this text file to csv?

  24. 24

    renaming file using shell script

  25. 25

    Batch file for loop convert to shell script

  26. 26

    Convert batch file for loop to shell script for loop

  27. 27

    Shell script to convert the date format in a file

  28. 28

    Shell script to validate a csv file column by column

  29. 29

    I need to copy the contents of a text file just before the first occurance of a specified word in shell script using shell script.

HotTag

Archive