DEV Community

Cover image for Append text in each line in a large CSV (unix style)
Leylow Lujuo
Leylow Lujuo

Posted on

1 3

Append text in each line in a large CSV (unix style)

Say you have a 10GB csv file and you want to add a text in the end of each line.

Obviously, opening it in vim work cut it

oh will it? ... let me confirm ... I tried and vim crushed :( ...

"So, what do we do?" I asked my conscious self while googling and stack-overflow-ing with 10+ tabs opened.

Viola! one of my stack-overflow tab came through and the answer was sed - a stream editor.

sed -r 's/text_to_find/text_to_replace/' input_file > output_file
# example
sed -r 's/\r/|the_text\r/' big_file.csv > output.csv

Basically, what it does here is;

-r this option represent extended regular expression

's/**\r**/|**the_text\r**/' the \r represent EOL, so replace EOL with the_text plus EOL(so that the output won't be a single line file)

The rest i.e... input and output file is self explanatory.

Writing is exhausting, I'm done. I have being told to be positive, so i'm scratching this and the line below.

Now i have to search for a cover image, smh.

Thanks for your one minute, hopefully I will write again.

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay