Need help for a simple script (i guess so...)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need help for a simple script (i guess so...)
# 1  
Old 07-01-2003
Need help for a simple script (i guess so...)

Hi all!

here is a sample of the file i am working on :


$ cat toto.txt
$20030613150250:Flux:ASS_IARD
20030613150250:Nombre d enregistrements Ecrits :27
20030613150250:Flux:ASS_TIER
20030613150250:Nombre d enregistrements Ecrits :27
20030613150251:Flux:ASS_PERS
20030613150251:Nombre d enregistrements Ecrits :52
20030613150251:Flux:LIEN_CONT
20030613150251:Nombre d enregistrements Ecrits :27
20030613150252:Flux:LIEN_EA
20030613150252:Nombre d enregistrements Ecrits :52
20030613150252:Flux:ASS_MODU
20030613150252:Nombre d enregistrements Ecrits :180


i want to obtain the following result :

ASS_IARD:27
ASS_TIER:27
ASS_PERS:52
LIEN_CONT:27
LIEN_EA:52
ASS_MODU:180

I already wrote something....Smilie :

if [ -f toto.txt ]
then
while read LINE
do
if [ `echo ${LINE} | grep Flux` ]
then
echo $LINE | awk -F ":" '{print $3}' >> ./LOG.wri
fi
done < toto.txt
fi

i know i feel pity for this one.......

PLEASE HELP Smilie

Regards

Howard
# 2  
Old 07-01-2003
Well, you had a good start.. there may be a shorter way to do this, but here's one way:
Code:
flag=0

if [ -f yourFile ]; then
 awk -F":" '{print $3}' yourFile |
 while read LINE
 do
  if [ $flag -eq 0 ]; then
   echo -n $LINE: >> resultFile
   flag=1
  else
   echo $LINE >> resultFile
   flag=0
  fi
 done
fi

 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Bash Script for Dice Game; Issue with if...else loop to verify user guess is within range

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have written a script for a dice game that: (1) tells user that each of the 2 die are 6 sided (Spots=6); (2)... (3 Replies)
Discussion started by: LaurenRose
3 Replies

2. Linux

How to execute a simple select script using a shell script?

Hi team, I have two select statements and need to run them using SYSDBA user select * from temp_temp_seg_usage; select segment_name, tablespace_name, bytes/ (1024*1024) UsedMb from dba_segments where segment_name='TEMP_TEMP_SEG_USAGE'; Need to run this using a shell script say named... (1 Reply)
Discussion started by: pamsy78
1 Replies

3. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

4. Shell Programming and Scripting

Give user 5 chances to guess my favorite color

I wrote a script to give a user 5 guesses on what is my favorite color but I it doesn't work. I've only been scripting for a couple weeks and need some help it seems simple but how do I give the user 5 guesses? (3 Replies)
Discussion started by: noob
3 Replies

5. Ubuntu

Stack overflow i guess while insmod

I have built kernel 2.6.35 on my Ubuntu system with some specific requirement. I also built some app defined module with the same kernel. I booted up the built version and I find it did not work properly as there is some gui and other modules missing problem. But the system booted up and I did... (0 Replies)
Discussion started by: sunilsukumar4u
0 Replies

6. UNIX for Dummies Questions & Answers

File Transfer that is not so trivial I guess

I have three computers A, B and C. To login to B and C I should use A because it has a SSH key. I don't have any other way of accessing these two computers. Now, if I need to transfer a file between B and C, I am unable to find a way that would work... because I don't know how to authenticate... (1 Reply)
Discussion started by: Legend986
1 Replies

7. Shell Programming and Scripting

guess the fault :)

I really cant understand whats wrong with this: File looks like this: 55 11 Code: cost=30 a= cut -c9-12 File let a=${a}+${cost} echo $a The answer echo should echo 11+30(cost) however the output looks like this: 11 30 And also is there anyway to grep $2 without awk? or maybe... (4 Replies)
Discussion started by: maskot
4 Replies

8. Shell Programming and Scripting

I need a simple script

Hi, I need a script which can apply 'cd' command . for example there is a directory: (myDirectory) #cd myDirectory (current dir is myDirectory) my script can do this: #do (current dir is myDirectory) (do is my script) Thanks. (2 Replies)
Discussion started by: mehmetned
2 Replies
Login or Register to Ask a Question