The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
remove first column of a space delimited txt ajp7701 Shell Programming and Scripting 1 04-18-2008 01:10 PM
Ksh Storing Multiple Files and reading each line in each file. developncode UNIX for Dummies Questions & Answers 1 04-08-2008 01:44 PM
Searching for text in a Space delimited File andyblaylock UNIX for Dummies Questions & Answers 6 11-27-2007 03:33 PM
Storing string with space rahul303 Shell Programming and Scripting 4 10-04-2007 07:26 AM
parsing a delimited line monkeys Shell Programming and Scripting 11 07-12-2006 03:24 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-23-2007
Registered User
 

Join Date: Jul 2007
Posts: 54
Stumble this Post!
Storing space delimited line in var with loop?

I have a script that converts a file into an html table. This script works fine for a 1 column table. However, I'm trying to do this for a multi-column table. My input file will look something like this:

a b c
d e f
g h i

My script basically works by taking in each line and putting that value into an html tag using a while loop reading each line. Now I need to make the script read each value of each line. The number of columns will be set so I figured what I could do is just have some sort of loop that stores each value of a line into a variable and then use it to build my table. I'm just not sure how to do that.

Is there a way to get the first line and have say these variables set like this $1=a, $2=b, $3=c? Each line will always be space delimited. Any help would be much appreciated. Thanks!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-23-2007
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,323
Stumble this Post!
Is the number of columns fixed? This will help with that:
Code:
#!/usr/bin/ksh

while read value1 value2 value3; do
# do your html conversion here
done < /path/to/input_file
Reply With Quote
  #3 (permalink)  
Old 08-23-2007
Registered User
 

Join Date: Jun 2007
Posts: 377
Stumble this Post!
use awk

hi
see follow example

input(a.txt):

Code:
a b c
d e f
code:

Code:
cat a.txt | awk '{
printf("$s,$s,$s",$1,upper($2),$3)
}' a.txt
output:

Code:
a B c
d E f
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0