|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
I am using the current script to cut out required fields from a flat file with several lines. #/bin/sh #/bin/sed grep denied /tmp/filename > deniedres cat -ve newfile > newfile1 linecount=`grep -c denied newfile1` linecount=`expr $linecount + 1` lc=1 until [ $lc = $linecount ] do echo $linecount echo $lc tempres=`grep denied newfile1|cut -d '$' -f $lc` echo "Tempres : $tempres" temp=1 event="event: " while [ $temp -lt 17 ] do line=`echo $tempres | cut -f $temp -d ';'` #echo " $line" if [ $temp = 1 ] || [ $temp = 3 ] || [ $temp = 16 ] then event=`echo $event $line` fi temp=`expr $temp + 1` done lc=`expr $lc + 1` done echo $event The script is supposed to go line by line and extrace and display the required fields by cutting them (fields 1,3 and 16) but what happens is that the grep denied newfile1|cut -d '$' -f $lc greps the first field of ALL the lines instead of looping line by line. is there anyway i can read from the file line by line and then extract out the fields, then proceed on to the next line? Thx in adv. |
|
#2
|
|||
|
|||
|
maybe try a different approach...
Try this code to read a file line by line:
PHP Code:
Using a while loop can take a long time to run and if you are parsing through larger input files you might want to try using sed or awk. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > reading from files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|