LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-13-2007, 03:00 PM   #1
exl75
Member
 
Registered: Mar 2007
Posts: 54

Rep: Reputation: 15
Question 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.

Last edited by exl75; 04-13-2007 at 03:38 PM.
 
Old 04-13-2007, 03:08 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.
 
Old 04-13-2007, 03:14 PM   #3
exl75
Member
 
Registered: Mar 2007
Posts: 54

Original Poster
Rep: Reputation: 15
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.

Last edited by exl75; 04-13-2007 at 03:39 PM.
 
Old 04-13-2007, 03:59 PM   #4
MOS JEFF-INITELY
Member
 
Registered: Sep 2006
Distribution: Windows .. MUAHAHAHA
Posts: 66

Rep: Reputation: 15
youll probably want to use cut and paste
 
Old 04-13-2007, 04:04 PM   #5
exl75
Member
 
Registered: Mar 2007
Posts: 54

Original Poster
Rep: Reputation: 15
Yeah! sure.Im not even gonna pay attention to your nonsense.

Last edited by exl75; 04-13-2007 at 04:06 PM.
 
Old 04-13-2007, 04:15 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

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


Cheers,
Tink
 
Old 04-14-2007, 01:57 AM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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

Last edited by jschiwal; 04-14-2007 at 01:59 AM.
 
Old 04-14-2007, 11:00 AM   #8
exl75
Member
 
Registered: Mar 2007
Posts: 54

Original Poster
Rep: Reputation: 15
Great,thanks a lot for your help.Its greatly appreciated I will try these commands and see what happens.
 
Old 04-16-2007, 08:06 AM   #9
MOS JEFF-INITELY
Member
 
Registered: Sep 2006
Distribution: Windows .. MUAHAHAHA
Posts: 66

Rep: Reputation: 15
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding the last command line argument (bash) pete1234 Programming 20 10-30-2006 10:20 AM
Command line utilities to use scanner + printer as a photocopier Ross Clement Linux - Software 1 10-10-2006 04:47 PM
Bash Script, no new line for echo command jorisb Linux - General 5 11-05-2005 12:08 AM
bash, command line ftp, and a delimma.. scoob8000 Linux - Networking 2 03-18-2005 05:22 PM
bash shell command line expansion hansi umayangan Linux - General 2 03-13-2005 11:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration