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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

i need to read a file and redirect

Reply to Message Icon

Name: deepesh1081
Date: October 20, 2007 at 23:14:15 Pacific
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



Sponsored Link
Ads by Google

Response Number 1
Name: Shadowlight
Date: December 9, 2007 at 06:08:51 Pacific
Reply:

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



0

Response Number 2
Name: deepesh1081
Date: December 10, 2007 at 22:23:35 Pacific
Reply:

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


0

Response Number 3
Name: deepesh1081
Date: December 10, 2007 at 22:25:07 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


ubuntu issues with dual b... unable to mount Linux/SUS...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: i need to read a file and redirect

what do i need to uncompress a tar.gz www.computing.net/answers/linux/what-do-i-need-to-uncompress-a-targz/10907.html

how to split a file with awk www.computing.net/answers/linux/how-to-split-a-file-with-awk/30036.html

Read a file from nt www.computing.net/answers/linux/read-a-file-from-nt/758.html