The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reading a binary file in text or ASCII format Nagendra High Level Programming 3 12-03-2008 06:11 PM
Help with reading text file bilal05 UNIX for Dummies Questions & Answers 1 04-12-2008 03:46 PM
Reading from Text file..... user__user3110 Shell Programming and Scripting 0 04-11-2008 05:18 AM
Reading text from a file LiquidChild Shell Programming and Scripting 12 05-30-2007 08:38 AM
reading text file jaan Shell Programming and Scripting 1 02-16-2004 08:43 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-02-2008
yajaykumar yajaykumar is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 8
Unhappy Help with Reading Text from file

Hello,

I am having a tough time reading data from an input text file.
The input file has lines of data which is comma seperated. Each line represents a record/row, but unfortunately the data in the individual column/fields have spaces and `cat filename`is not returning entire line ( to read individual records).

How can I read individual records from this file? Is there a way to do it?
Below is a sample of the input file and it is also attached with this post.

Content Type,Author,Initial Submit Date,Task Name,Task Start Date,Task End Date,Task Owner,Completion Date
Workflow Properties,wcm_master,,,Workflow Properties,Workflow Properties,Workflow Properties,Workflow Properties
Workflow Properties,wcm_master,,,Workflow Properties,Workflow Properties,Workflow Properties,Workflow Properties
Workflow Properties,wcm_master,1217361943,TaskAddFile,Workflow Properties,Workflow Properties,Workflow Properties,Workflow Properties
Workflow Properties,wcm_master,1217362058,TaskAddFile,Workflow Properties,Workflow Properties,Workflow Properties,Workflow Properties
Email Test Flow,wcm_master,1217971876,TaskAddFile,Email Test Flow,Email Test Flow,Email Test Flow,Email Test Flow
CGI Test,n1plomen,1219776115,TaskAddFile,CGI Test,CGI Test,CGI Test,CGI Test
CGI Test,n1plomen,1219776268,TaskAddFile,CGI Test,CGI Test,CGI Test,CGI Test
CGI Test,n1plomen,1219776333,TaskAddFile,CGI Test,CGI Test,CGI Test,CGI Test
CGI Test,n1plomen,1219776417,TaskAddFile,CGI Test,CGI Test,CGI Test,CGI Test
CGI Test,n1plomen,1219776470,TaskAddFile,CGI Test,CGI Test,CGI Test,CGI Test
CGI Test,n1plomen,1219787503,TaskAddFile,CGI Test,CGI Test,CGI Test,CGI Test
CGI Test,n1plomen,1219787605,TaskAddFile,CGI Test,CGI Test,CGI Test,CGI Test
Email Test Flow,wcm_author,1219865848,TaskAddFile,Email Test Flow,Email Test Flow,Email Test Flow,Email Test Flow
Email Test Flow,wcm_author,1219865871,TaskAddFile,Email Test Flow,Email Test Flow,Email Test Flow,Email Test Flow
Email Test Flow,wcm_author,1219865908,TaskAddFile,Email Test Flow,Email Test Flow,Email Test Flow,Email Test Flow


Your help is highly appreciated!

Thank you,
Ajay
Attached Files
File Type: txt testwf.txt (1.6 KB, 12 views)
  #2 (permalink)  
Old 09-02-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,884
The "backtick" operators strip out the newlines and replace them with spaces, so yeah, that's a problem for you. You need to do something like this instead:
Code:
cat your-file | while read line; do 
  something... something to $line;
done
  #3 (permalink)  
Old 09-02-2008
yajaykumar yajaykumar is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 8
otheus,

Thanks a lot! It worked.
  #4 (permalink)  
Old 09-02-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Or without cat:
(remove the -r flag if your shell does not support it)

Code:
while IFS= read -r;do
  printf "--> %s\n" "$REPLY"
done<testwf.txt
For large files consider using another parsing tool, not shell loops.
  #5 (permalink)  
Old 09-02-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Cool

Can you use something like the following?

Code:
while read zf
   do
   cont_type=$(echo "$zf" | cut -d"," -f1)
   echo "Content Type ="$cont_type
   author=$(echo "$zf" | cut -d"," -f2)
   echo "Author ="$author
done <input_file
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0