LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What bash command line utilities do I need? (https://www.linuxquestions.org/questions/linux-newbie-8/what-bash-command-line-utilities-do-i-need-545847/)

exl75 04-13-2007 03:00 PM

What bash command line utilities do I need?
 
I want to create 2 column list.The first column goes from 1-5,the second column being the number of entries in the file /data/share/files/text that has the
number of characters listed in the first column.The content of the text file is copied below:
L
Lin
Linux
Dis
Dist
Book
Downl
Bookm
Press
green

I dont know the commands or combination of commands to do this.Any help would be greatly appreciated.

jschiwal 04-13-2007 03:08 PM

Your example text file has entries with more than 5 characters. You didn't indicate what to do if a line has more than 5 characters.

I think you want to read the info bash manual. You can assign a line to a variable and use a form of variable reference that returns the number of characters in the variable. Also read the section on arrays in bash. You don't need to use any core utils or text utils for this simple example. Bash can count the characters for you.

I'm just giving you a hint in the right direction because this looks like a homework assignment.

exl75 04-13-2007 03:14 PM

No,Its not!This is something Im trying to do on my own.But,..I will try to read on arrays in bash and see if it helps.An example would be nice to steer me in the right direction.Not sure..a sed? a grep? an awk? or a combination of all of them.

MOS JEFF-INITELY 04-13-2007 03:59 PM

youll probably want to use cut and paste

exl75 04-13-2007 04:04 PM

Yeah! sure.Im not even gonna pay attention to your nonsense.

Tinkster 04-13-2007 04:15 PM

These actually *ARE* command-line tools with what may
appear to be /strange/ names for someone with a Gooey
background ....


Cheers,
Tink

jschiwal 04-14-2007 01:57 AM

If the size of the file isn't too large, you can read it into an array like this:
text=( $( cat file) )

Try playing with these commands, and reference the bashref manual to see what they are doing.
Code:


$ ifs=$IFS
$ IFS='
> '

$ example1=($(cat /etc/hosts))

$ IFS=$ifs

$ wc -l /etc/hosts
21 /etc/hosts

$ echo ${example1[0]}

$ echo ${example1[20]}

$ echo ${#example1[*]}

$ echo ${#example1[0]}

$ echo ${#example1[0]}

$ echo ${example1[0]} | wc -c

Also download the Advanced Bash Scripting guide from the www.tldp.org website. It consists entirely of well commented examples that you can try yourself.
http://tldp.org/LDP/abs/abs-guide.pdf

exl75 04-14-2007 11:00 AM

Great,thanks a lot for your help.Its greatly appreciated I will try these commands and see what happens.

MOS JEFF-INITELY 04-16-2007 08:06 AM

Quote:

Originally Posted by exl75
Yeah! sure.Im not even gonna pay attention to your nonsense.

can you be more ignorant?

man cut
man paste

these are commands


All times are GMT -5. The time now is 02:48 PM.