Struggling with Bash Scripting: Seeking Guidance for CSV Processing

0
2
Asked By CuriousCoder99 On

I'm really frustrated with learning Bash scripting. Unlike other programming languages that have structured resources and exercises, Bash seems to lack that sort of guidance. I've taken numerous courses but they didn't help me much since they don't provide a problem-solving approach. I love building and want to create things, but I find myself relying heavily on ChatGPT and Google just to remember simple syntax or concepts, like how to loop through arrays.

Right now, I'm trying to process a CSV file with two columns separated by commas. Here's a quick look at the data structure:

U-DLCI,6
C/R,1
EA,1
L-DLCI,4
FECN,1
BECN,1
DE,
EA,1

The goal is to allocate units of distance based on the values in the second column and to print the labels centered in those allocated spaces. For example, U-DLCI with a value of 6 means I need to allocate 6 units of space and print the label centered within that space. After processing a few lines, I want to jump to a new line when the allocated space reaches a total of 8 units.

This project feels so much simpler in Java, where I could leverage built-in CSV handling. Why does Bash seem so difficult and convoluted for such tasks?

3 Answers

Answered By TechieTurtle84 On

It sounds like you're trying to use Bash for projects that might be better suited for a general-purpose programming language. While Bash is great for command-line tasks, if you're dealing with more complex programming needs, maybe you could consider using Python or something similar. Just a thought!

Answered By DevDude2022 On

You might find it helpful to check out 'You Suck At Programming' on YouTube, which can make Bash scripting more relatable. There are also some good resources like 'BashFAQ' that lay out Bash concepts clearly, similar to programming textbooks. Just keep in mind that Bash excels in certain areas but isn't always the best fit for everything you're trying to do!

Answered By CodeWizard77 On

Try looking into tools like awk, which are actually designed for processing text and can handle CSVs quite efficiently. Bash itself is limited and mainly acts as a glue for other programs. If you're doing substantial data manipulation, a language like Python is generally recommended due to its ease of use and CSV libraries. You might find that it's much more pleasant to work with!

GeekyGiraffe -

Haha, true! Python has a CSV module that makes life so much easier. Maybe try that next time!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.