Writing output to a file in columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Writing output to a file in columns
# 1  
Old 02-03-2015
Writing output to a file in columns

Hi

I am trying to write output to a file in columns
I have file in the follwoing:
Code:
# cat file
abc
def
#

I am trying to write next output as like

Code:
# cat file
abc 123
def 345
#

Smilie
# 2  
Old 02-03-2015
Hello Priya Amaresh,

Could you please explain by which logic you want output like as follows.
Code:
abc 123
def 345

It is advisable to always provide complete information about your requirement with your os details and what you have tried so far,
it will help us too to understand your requirement.

Thanks,
R. Singh

Last edited by RavinderSingh13; 02-03-2015 at 04:54 AM..
# 3  
Old 02-03-2015
HI Ravinder

I am trying to write into a file in the form of array.
Whereas the column attribute remains constant and row entries will be held.
I tried the following
Code:
declare -A matrix
num_columns=3
num_rows=2
for ((i=1;i<=num_rows;i++)) do
echo "Enter the class of student $i:"
read name
matrix[$i,1]=$oss >> /home/info
done
cat /home/info

here matrix[$i,1] ==> means row value varies but column remains one.. but I missing a link between column variable "num_columns" and "matrix[$i,1]"

Could you please tel me how to enter variables into matrix keeping column value constant for a while and varying row values
# 4  
Old 02-03-2015
Is that homework?
# 5  
Old 02-03-2015
AFAIK: Bash doesnt allow double indexed arrays (matrix[$i,1] - or whatever the proper term is) -- that much regarding to 'here matrix[$i,1] means'...

Also, while a list of students of a class can be easy to handle, to manage students of classes, i'd recomend to go csv (tablesheet) or mysql (database)...
In both cases the script will have increased difficulty.

Other than that, awaiting answer to RudiC's question.
And still missing the 'logic' behind it, i cant follow the current description - to my understanding, you're just stating the obvious, but not the reason behind it.
# 6  
Old 02-03-2015
@sea

You can use multi-dimensional arrays in bash, but it is a bit of a messy eval hack job
This User Gave Thanks to pilnet101 For This Post:
# 7  
Old 02-03-2015
Actually, with an associative array, this looks like a multidimensional array:
Code:
echo ${!matrix[@]}
2,1 1,1

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Wrong output when writing to file

Hello, I am having problem while redirecting output to a file where as on console output is proper. for dir in */; do printf "%s, " "$dir"; ls -m "$dir"; echo; done > output.txt Output of above command is coming in single line but when i am redirecting output to a file, single line i... (10 Replies)
Discussion started by: Manoj Rajput
10 Replies

2. Shell Programming and Scripting

Getting output with sed without writing to a file

HI I am trying to grep 3 characters from hostname and append a character at the end. I tried as in the following: root@abag3:~# hostname | cut -c1-3 hyu Now I am trying to append "g" at the end of this output as in the following. root@abag3:~# hostname | cut -c1-3 | sed -s... (4 Replies)
Discussion started by: Priya Amaresh
4 Replies

3. Shell Programming and Scripting

Comparing Columns and writing a new file

I have a table with one column File1.txt 1 2 3 4 5 6 7 8 9 10 Another table with two columns; This has got a subset of entries from File 1 but not unique because they have differing values in col 2. File2.txt 1 a 2 d 2 f 6 r 6 e (3 Replies)
Discussion started by: cs_novice
3 Replies

4. Shell Programming and Scripting

Cat writing only one record in the output file

Hi All, I have an input file containing data as below: Input.DAT XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|B|YY|111111111|111111111|111111111|111111111|15|3|NNNNNN|Y|3|AAA|111111111... (11 Replies)
Discussion started by: sagar.cumar
11 Replies

5. Shell Programming and Scripting

validating data in columns and writing them to new file

I have a file that contains records in the below format: 23857250998423948239482348239580923682396829682398094823049823948 23492780582305829852095820958293582093585823095892386293583203248 23482038509825098230958235234230502958205983958235820358205892095... (10 Replies)
Discussion started by: shellhelp
10 Replies

6. UNIX for Dummies Questions & Answers

Writing a script that will take the first line from each file and store it in an output file

Hi, I have 1000 files names data1.txt through data1000.txt inside a folder. I want to write a script that will take each first line from the files and write them as output into a new file. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

7. Shell Programming and Scripting

Writing only timing statistics output of Timer to File

I'm running long integrations on a remote server, and I'm working in terminal in a tcsh shell. I'm looking to write ONLY the timing statistics to a file. For example: $time ls >timer.out writes both the files in my current directory & the timer statistics to the file timer.out. I only... (2 Replies)
Discussion started by: elemonier
2 Replies

8. Shell Programming and Scripting

writing the output of SQL into one file

Hi All, Please help me writing the below script. I have two sql queries. 1. Select count(1),Client_id from TABLE_A group by Client_id; 2. Select count(1),Client_id from TABLE_B group by Client_id; I need the output of above two sql queries in a single file. The output 2nd query should be... (4 Replies)
Discussion started by: 46019
4 Replies

9. Shell Programming and Scripting

Writing output into different files while processing file using AWK

Hi, I am trying to do the following using AWK program. 1. Read the input data file 2. Parse the record and see if it contains errors 3. If the record contains errors, then write it into Reject file, else, write into usual output file or display it on the screen Here is what I have done -... (6 Replies)
Discussion started by: vidyak
6 Replies
Login or Register to Ask a Question