LinuxQuestions.org
Visit Jeremy's Blog.
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 07-16-2007, 03:08 PM   #1
jimmy512
Member
 
Registered: Oct 2006
Location: London
Distribution: Arch
Posts: 183

Rep: Reputation: 31
Question Reading From a Column in a File


Small problem here - I am writing a script, and this script needs to read a character in a specific column of a text file (a log in this case). I know that I can use grep to read individual lines but I am not sure how to accomplish the same with columns instead.

Also, is there an easy way to read the percentage output from a wget download without processing the wget-log file when using wget -b?

Thanks for any answers given.
 
Old 07-16-2007, 03:14 PM   #2
jakykong
Member
 
Registered: Apr 2006
Location: Washington
Distribution: Debian Gnu/Linux Lenny on AMD64x2 (32-bit mode), an AMD Sempron 64 laptop, debian, 32bit
Posts: 101

Rep: Reputation: 15
Check out the 'cut' program,
Code:
man cut
It is able to display only a specific column or columns in a text file, either by the specific character or by the column, like this:

Code:
# echo "this is a test" | cut -c2,3
hi
# echo "this is a test" | cut -d" " -f3
a
#
It should solve both of your problems.
 
Old 07-16-2007, 03:19 PM   #3
jimmy512
Member
 
Registered: Oct 2006
Location: London
Distribution: Arch
Posts: 183

Original Poster
Rep: Reputation: 31
It works! Thanks a lot. It would have taken me hours to work that out!
 
Old 07-16-2007, 11:49 PM   #4
jakykong
Member
 
Registered: Apr 2006
Location: Washington
Distribution: Debian Gnu/Linux Lenny on AMD64x2 (32-bit mode), an AMD Sempron 64 laptop, debian, 32bit
Posts: 101

Rep: Reputation: 15
No problem. Glad I could help
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
ls -> Column Order daletaylor Linux - Newbie 3 06-22-2007 10:59 AM
Erratic column? Hitboxx LQ Suggestions & Feedback 3 03-03-2007 10:53 AM
add id in the first column alaios Linux - General 1 11-19-2004 06:49 AM
Column limit agallant Programming 1 08-05-2004 10:58 AM
add new column Eddie9 Linux - General 2 04-09-2002 12:05 PM


All times are GMT -5. The time now is 03:15 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration