LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-24-2006, 08:32 PM   #1
STAGED
LQ Newbie
 
Registered: Jun 2005
Location: Agoura Hills, CA
Distribution: FC3
Posts: 17

Rep: Reputation: 0
script to read file into array


This c an't possibly be the first request like this. But I was wondering if there's a nice script already done to something like (i.e., not exactly like) the following:

i.) read a file (consisting of 8 columns separated by spaces)
ii.) generating a file of just the first two columns
iii.) writing the two columns to file

Thanks
 
Old 01-24-2006, 11:06 PM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
here is a quality starting bit.. you figure out the rest.. (which is very little)

`cat a.file | cut -d ' ' -f1,2`

<edit> this had better not have been homework.. i will find your teacher..

Last edited by xhi; 01-24-2006 at 11:07 PM.
 
Old 01-25-2006, 06:40 AM   #3
STAGED
LQ Newbie
 
Registered: Jun 2005
Location: Agoura Hills, CA
Distribution: FC3
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks very much. This is not homework, just self-enlightning.

Best regards.
 
Old 01-25-2006, 06:59 AM   #4
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
Code:
awk -F" " '{print $1, $2}' oldfile > newfile
 
Old 01-27-2006, 08:06 PM   #5
STAGED
LQ Newbie
 
Registered: Jun 2005
Location: Agoura Hills, CA
Distribution: FC3
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks for the command line utility!
 
  


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
[Shell] Read a File from script yussef Programming 4 08-19-2008 04:26 AM
how to read a file into an array cyb0rg777 Programming 4 09-23-2005 08:12 AM
Shell script to read from csv file hendemeg Programming 1 05-11-2004 08:23 PM
Script to read a simple text file ravykanth Linux - Newbie 9 10-22-2003 04:15 AM
script question? read from a file myketech Linux - General 5 03-06-2003 07:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:31 PM.

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