Sponsored Content
Top Forums Shell Programming and Scripting [Shell] How make colums in text file ?? Post 82819 by Sabari Nath S on Wednesday 7th of September 2005 01:10:17 AM
Old 09-07-2005
Quote:
Originally Posted by parola
hi,

i have little pb, i would like make a colums, but my server not recongize "\t" or i write wrong.... and iam little noobs and no know awk...

Code:
#!/bin/ksh 
#---------------------------------------------------------------------------- 
# Fichiers : ctrl.sh et ctrl2005.txt 
#--------------------------------------------------------------------------- 

# variables 
chemin="/usr/eric/fichiers/" 
ctrl="/usr/eric/booba/ctrl.txt" 

# path 
cd $chemin 

# Date 
echo "Entrée past Date and Month:\c" 
read dater 

# grep de "SFR" "ORA" "BOU" 

echo "SFR" > $ctrl 
grep -c "SFR" baba.$dater* >> $ctrl 

echo "ORA" >> $ctrl 
grep -c "ORA" baba.$dater* >> $ctrl 

echo "BOU" >> $ctrl 
grep -c "BOU" baba.$dater* >> $ctrl


this give ctrl.txt

Code:
SFR 
baba.18080810:3 
baba.18080906:2 
baba.18081152:35 
baba.18081426:78 
baba.18081645:121 
baba.18081710:27 
baba.18081851:24 
baba.18082010:18 
baba.18082030:2 
ORA 
baba.18080810:25 
baba.18080906:3 
baba.18081152:64 
baba.18081426:24 
baba.18081645:9 
baba.18081710:15 
baba.18081851:84 
baba.18082010:0 
baba.18082030:10 
BOU 
baba.18080810:113 
baba.18080906:10 
baba.18081152:46 
baba.18081426:9 
baba.18081645:0 
baba.18081710:3 
baba.18081851:5 
baba.18082010:4 
baba.18082030:0

and i have change this :

Code:
# Multi grep de "SFR" "ORA" "BOU" 

echo "SFR" > $ctrl 
grep -c "SFR" baba.$dater* >> $ctrl 

echo "ORA" >> $ctrl 
grep -c "ORA" baba.$dater* >> $ctrl 

echo "BOU" >> $ctrl 
grep -c "BOU" baba.$dater* >> $ctrl

by this one :

Code:
# grep de "sfr" "orange" "bouygue" 
SFR=`grep -c "sfr" titiyo.$dater*` 
ORA=`grep -c "orange" titiyo.$dater*` 
BOU=`grep -c "bouygue" titiyo.$dater*` 

echo "SFR\t\tORA\t\tBOU" >$ctrl 
echo "$SFR\t\t$ORA\t\t$BOU" >>$ctrl

and no works propely

i would like this output in my text file ctrl.txt :

Code:
Files                  SFR      ORA      BOU  
baba.18080810       3       25      113 
baba.18080906       2        3       10 
baba.18081152      35       64       46 
baba.18081426      78       24        9 
baba.18081645     121        9        0 
baba.18081710      27       15        3 
baba.18081851      24       84        5 
baba.18082010      18        0        4 
baba.18082030       2       10        0

Help Me ........

PS: Sorry For My English, Is Not My Native Language.
This shud give u a well formatted output ... try out .. .

echo " -----------------------------------------------------------------" >> $ctrl
echo "| File | SFR | ORA | BOU |" >> $ctrl
echo " -----------------------------------------------------------------" >> $ctrl
for filename in `ls baba.$dater*`
do
SFR_count=`grep -c SFR $filename`
ORA_count=`grep -c ORA $filename`
BOU_count=`grep -c BOU $filename`
printf "|%21s|%16s|%12d|%13d|\n" $filename $SFR_count $ORA_count $BOU_count >> $ctrl
done
echo " -----------------------------------------------------------------" >> $ctrl
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to make a number in a text file a variable?

OK this one sounds like it should be a natural... it must be possible to send a number say 200 to a text file and later use it as a variable? yada yada > file.txt how would I retrieve that number to use as a variable? Is this possible? (5 Replies)
Discussion started by: nortypig
5 Replies

2. UNIX for Dummies Questions & Answers

search all file for particular text and make changes to line 3

Hi All, I am sitting on HPUX. I want to change the exit into #exit, which appears into 3red line of code in shell scripting, wondering how shell script to be called up to perform action. I have following code in all files. Now, I need to find the text exit and replace into #exit. #!/sbin/sh... (10 Replies)
Discussion started by: alok.behria
10 Replies

3. Shell Programming and Scripting

Rearranging the colums in a tab delimited file

I want to rearrange some of my columns in my dat file; how do i do this using a script Suppose, I have an input file like this: BASENAME STREETTYPE PREFIX SUFFIX HOUSENUMBER BUILDUP ORDER8 ORDER2 ORDER1 ISOCOUNTRYCODE POSTALCODE SILVER LAKE RD NW 1135 NEW BRIGHTON RAMSEY MINNESOTA USA 55112... (4 Replies)
Discussion started by: ramky79
4 Replies

4. Shell Programming and Scripting

Make a table from a text file

Hi, I have a pipe separated text file. Can some someone tell me how to convert it to a table? Text File contents. |Activities|Status1|Status2|Status3| ||NA|$io_running2|$io_running3| |Replication Status|NA|$running2|$running3| ||NA|$master2|$master3|... (1 Reply)
Discussion started by: rocky88
1 Replies

5. Shell Programming and Scripting

Reading columns from a text file and to make an array for each column

Hi, I am not so familiar with bash scripting and would appreciate your help here. I have a text file 'input.txt' like this: 2 3 4 5 6 7 8 9 10 I want to store each column in an array like this a ={2 5 8}, b={3 6 9}, c={4 7 10} so that i can access any element, e.g b=6 for the later use. (1 Reply)
Discussion started by: Asif Siddique
1 Replies

6. Shell Programming and Scripting

Reading colums from a text file

Hi all, I have a text file that has (4) columns. There are about 300 lines on this file. It is a plain text file. I am looking to write a simple script that will read each line from the file and generate another text file. The file looks something like this: These are the columns: ... (4 Replies)
Discussion started by: adamw
4 Replies

7. UNIX for Dummies Questions & Answers

Find the timestamp difference between two different colums in a file

Sample Input File 2014/10/09 CDE876172588765 00:09:45 00:10:10 200 200 11.7093 2014/10/09 CDE366134588757 01:04:34 01:04:54 210 210 9.8898 2014/10/09 CDE765172345745 03:05:46 03:06:01 100 100 10.0601 2014/10/09 ... (8 Replies)
Discussion started by: rpm120
8 Replies

8. Shell Programming and Scripting

Make copy of text file with columns removed (based on header)

Hello, I have some tab delimited text files with a three header rows. The headers look like, (sorry the tabs look so messy). index group Name input input input input input input input input input input input... (9 Replies)
Discussion started by: LMHmedchem
9 Replies

9. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

10. UNIX for Beginners Questions & Answers

How to make partitions in a text file?

Suppose I have a file named intro.txt and its content is as follows My name is Ankit. I am 18. I am a college student. So I want make partitions in this and store it as 1. name.txt - I am 18. 2. age.txt - I am 18. 3. student.txt -I am a college student. How do I do that in terminal? edit... (1 Reply)
Discussion started by: ANKIT ROY
1 Replies
All times are GMT -4. The time now is 11:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy