Computing.Net > Forums > Linux > i need to read a file and redirect

i need to read a file and redirect

Reply to Message Icon

Original Message
Name: deepesh1081
Date: October 20, 2007 at 23:14:15 Pacific
Subject: i need to read a file and redirect
OS: linux
CPU/Ram: amd64
Comment:

i need to do "read while" from a file and redirect teh output in different file.

may be these thing make it clear:
cat filo |while read file
cat $file | grep arch |cut -c37-68 >> test

as filo contains name of some log files and i want:
cat filo
arch_backup_prdcma.101307_00:11:01
arch_backup_prdcma.101307_00:11:02
arch_backup_prdcma.101307_00:11:05
arch_backup_prdcma.101307_00:11:07

cat arch_backup_prdcma.101307_00:11:01 > test1
cat arch_backup_prdcma.101307_00:11:02 >test2
and so on but i cant....?


any help??

deepesh1081@gmail.com


Report Offensive Message For Removal

Response Number 1
Name: Shadowlight
Date: December 9, 2007 at 06:08:51 Pacific
Subject: i need to read a file and redirect
Reply: (edit)

(( N = 1 ))
cat filo | while read LINE
do
cat ${LINE} > testfile{N}
(( N += 1 ))
done



Report Offensive Follow Up For Removal

Response Number 2
Name: deepesh1081
Date: December 10, 2007 at 22:23:35 Pacific
Subject: i need to read a file and redirect
Reply: (edit)

i got what i was looking for . thanks for the workaround


!/bin/bash
#ls -l |grep 1013 |cut -c55-88 > filo
#ls -l |grep `date "+%m%d%y"` |cut -c55-88 > filo
ls -l |grep `date "+%m%d%y"` |cut -f 15 -d ' '> filo
rm test
export c=`wc -l filo |cut -c1`
cat filo |while read file
do
cat $file | grep arch |cut -c37-68 >> test
done


#ls -l |grep 1013 |cut -c55-88 > tilo
#ls -l |grep `date "+%m%d%y"` |cut -c55-88 > tilo
ls -l |grep `date "+%m%d%y"` |cut -f 15 -d ' ' > tilo
rm back
#export c=`wc -l tilo |cut -c1`
cat tilo |while read tile
do
export u=`cat $tile | grep arch|wc -l| cut -c8-9`
for ((i=0;i<$u;i++))
do
cat $tile|grep backup >>back
done
done

paste test back > back.out
sed 's, ,|,g' back.out > final.out


deepesh1081@gmail.com


Report Offensive Follow Up For Removal

Response Number 3
Name: deepesh1081
Date: December 10, 2007 at 22:25:07 Pacific
Subject: i need to read a file and redirect
Reply: (edit)

here is the demo


this is the demo


sysadmins-computer-2:~/oracle> ll arch_backup_prdcm* ( the dir where
ur files are located)
-rw-r--r-- 1 dchaudha dchaudha 318 Nov 10 23:12
arch_backup_prdcma.101307_00:11:01
-rw-r--r-- 1 dchaudha dchaudha 222 Nov 6 15:44
arch_backup_prdcma.101307_00:11:02
-rw-r--r-- 1 dchaudha dchaudha 222 Nov 6 15:44
arch_backup_prdcma.101307_00:11:05
-rw-r--r-- 1 dchaudha dchaudha 222 Nov 6 15:44
arch_backup_prdcma.101307_00:11:07

sysadmins-computer-2:~/oracle> cat arch* (content of all files)
archive log filename=/prdcma/arch01/arch_prdcma_2790_1_631629058.log
recid=2800 stamp=635850606
archive log filename=/prdcma/arch01/arch_prdcma_2795_1_631629054.log
recid=2800 stamp=635850608
archive log filename=/prdcma/arch01/arch_prdcma_2796_1_631629054.log
recid=2801 stamp=635850617
Finished backup at 14-OCT-07

archive log filename=/prdcma/arch01/arch_prdcma_2767_1_631629055.log
recid=2800 stamp=635850608
archive log filename=/prdcma/arch01/arch_prdcma_2768_1_631629055.log
recid=2801 stamp=635850617
Finished backup at 10-OCT-07

archive log filename=/prdcma/arch01/arch_prdcma_2797_1_631629055.log
recid=2800 stamp=635850608
archive log filename=/prdcma/arch01/arch_prdcma_2798_1_631629055.log
recid=2801 stamp=635850617
Finished backup at 13-OCT-07

archive log filename=/prdcma/arch01/arch_prdcma_2695_1_631629054.log
recid=2800 stamp=635850608
archive log filename=/prdcma/arch01/arch_prdcma_2696_1_631629054.log
recid=2801 stamp=635850617
Finished backup at 19-OCT-07


sysadmins-computer-2:~/oracle> ./final

sysadmins-computer-2:~/oracle> cat final.out
arch_prdcma_2790_1_631629058.log|Finished backup at 14-OCT-07
arch_prdcma_2795_1_631629054.log|Finished backup at 14-OCT-07
arch_prdcma_2796_1_631629054.log|Finished backup at 14-OCT-07
arch_prdcma_2767_1_631629055.log|Finished backup at 10-OCT-07
arch_prdcma_2768_1_631629055.log|Finished backup at 10-OCT-07
arch_prdcma_2797_1_631629055.log|Finished backup at 13-OCT-07
arch_prdcma_2798_1_631629055.log|Finished backup at 13-OCT-07
arch_prdcma_2695_1_631629054.log|Finished backup at 19-OCT-07
arch_prdcma_2696_1_631629054.log|Finished backup at 19-OCT-07
sysadmins-computer-2:~/oracle>


and the final script

sysadmins-computer-2:~/oracle> cat final
#!/bin/bash
ls -l |grep 1013 |cut -c55-88 > filo #### check the output of
the command####
rm test
export c=`wc -l filo |cut -c1`
cat filo |while read file
do
cat $file | grep arch |cut -c37-68 >> test
done


ls -l |grep 1013 |cut -c55-88 > tilo
rm back
#export c=`wc -l tilo |cut -c1`
cat tilo |while read tile
do
export u=`cat $tile | grep arch|wc -l| cut -c8-9`
for ((i=0;i<$u;i++))
do
cat $tile|grep backup >>back
done
done

paste test back > back.out
sed 's, ,|,g' back.out > final.out


####################end##################

sysadmins-computer-2:~/oracle> ls -l |grep 1013 |cut -c55-88 ( as
spacing matter so just varify)
arch_backup_prdcma.101307_00:11:01
arch_backup_prdcma.101307_00:11:02
arch_backup_prdcma.101307_00:11:05
arch_backup_prdcma.101307_00:11:07


deepesh1081@gmail.com


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: i need to read a file and redirect 

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software