Storing space delimited line in var with loop?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Storing space delimited line in var with loop?
# 1  
Old 08-24-2007
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!
# 2  
Old 08-24-2007
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

# 3  
Old 08-24-2007
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

2. Shell Programming and Scripting

Help/Advise please for converting space delimited string variable to comma delimited with quote

Hi, I am wanting to create a script that will construct a SQL statement based on a a space delimited string that it read from a config file. Example of the SQL will be For example, it will read a string like "AAA BBB CCC" and assign to a variable named IN_STRING. I then concatenate... (2 Replies)
Discussion started by: newbie_01
2 Replies

3. Shell Programming and Scripting

How to make tab delimited file to space delimited?

Hi How to make tab delimited file to space delimited? in put file: ABC kgy jkh ghj ash kjl o/p file: ABC kgy jkh ghj ash kjl Use code tags, thanks. (1 Reply)
Discussion started by: jagdishrout
1 Replies

4. UNIX for Dummies Questions & Answers

Changing only the first space to a tab in a space delimited text file

Hi, I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

5. Shell Programming and Scripting

Storing Grep Files into Var and comparing it

Hi, I was working on the password policy settings of Solaris where i wanted to grep the results of MINDIFF and comparing it to if else to make it into a auditing script. I stored the grep into VAR1 and compare it if MINDIFF=3 but it doesnt work. Can anyone help me with it? !#/bin/bash ... (2 Replies)
Discussion started by: Jareddd
2 Replies

6. Shell Programming and Scripting

How to convert a space delimited file into a pipe delimited file using shellscript?

Hi All, I have space delimited file similar to the one as shown below.. I need to convert it as a pipe delimited, the values inside the pipe delimited file should be as highlighted... AA ATIU2345098809 009697 005374 BB ATIU2345097809 005445 006518 CC ATIU9685098809 003215 003571 DD... (7 Replies)
Discussion started by: nithins007
7 Replies

7. Shell Programming and Scripting

Convert Rows to Space Delimited Line

Hello, I would like to convert a list of rows to a space separated line. Any ideas? Input file: "Administration Tools" "Design Suite" "Dial-up Networking Support" "Editors" desired output "Administration Tools" "Design Suite" "Dial-up Networking Support" "Editors" Thanks,... (4 Replies)
Discussion started by: jaysunn
4 Replies

8. UNIX for Dummies Questions & Answers

Converting Space delimited file to Tab delimited file

Hi all, I have a file with single white space delimited values, I want to convert them to a tab delimited file. I tried sed, tr ... but nothing is working. Thanks, Rajeevan D (16 Replies)
Discussion started by: jeevs81
16 Replies

9. Shell Programming and Scripting

Storing string with space (urgent)

hi i have a file content like my_file: 1US8738297897918000 000 000 i used while IFS= read line do echo "$line" | grep '^\ then last=`echo "$line" | cut -c 3-20` echo "$last" fi done < $my_file but it is writing blank spaces into the o/p fie (1 Reply)
Discussion started by: Satyak
1 Replies

10. Shell Programming and Scripting

Storing string with space

Hi all I am trying this simple command: a="abc abc" echo $a output is: abc abc But expected output shoould be :abc abc i.e spaces in real string are geting truncated to one space everytime. Plz Help. (4 Replies)
Discussion started by: rahul303
4 Replies
Login or Register to Ask a Question