|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Reading Specific line from a file??
Hello!
I need to process an unknown number of files each time to remove special characters and remove trailing blanks. My approach is this (I realise it's probably not the best code in the world but I like to keep things simple )Code:
ls file* > list1
wc -l list1 > list2
COUNT1=1
COUNT2=`awk '{print substr($1,1,4)}' list2`
COUNT2=`expr $COUNT2 + 1`
while [ $COUNT1 -ne $COUNT2 ]
do
** read line from list1 using $COUNT1 to specify the next
line at each pass. so, pass1 read line 1;
pass 2 read line 2, etc. This is where I'm stuck! How can I do it???
<process file>
COUNT1=`expr $COUNT1 + 1`
done
loop through each row from list1.lst one at a time and process each file using sed. so Problem is that I can't work out how to loop through 1 line at a time from list1.lst Can you help me? Thanks Rich |
|
#2
|
|||
|
|||
|
This is how to read from a file. You can add a break statement iside an if block to end the loop early
Code:
#!/bin/ksh
let linecount=1
while read record
do
echo $record
let linecount=$linecount+1
if [ $linecount -eq $COUNT2 ]; then
break;
fi
done < list2
I really don't understand your question. |
|
#3
|
|||
|
|||
|
Jim
That was exactly that I was looking for! Many thanks for your help and expertise, Rich |
|
#4
|
|||
|
|||
|
Not My Way
[QUOTE=rgord1]Hello!
I need to process an unknown number of files each time to remove special characters and remove trailing blanks. My approach is this (I realise it's probably not the best code in the world but I like to keep things simple )Code:
ls file* > list1
wc -l list1 > list2
COUNT1=1
COUNT2=`awk '{print substr($1,1,4)}' list2`
COUNT2=`expr $COUNT2 + 1`
while [ $COUNT1 -ne $COUNT2 ]
do ......
COUNT1=`expr $COUNT1 + 1`
done
print line 200 (if present) Code:
sed-n '200p' print lines 7-10 Code:
sed -n '7,10p' print line matching aaa at line begin Code:
sed -n '/^aaa/p' print lines between aaa and zzz at line begin Code:
sed -n '/^aaa/,/^zzz/p' and so on |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Reading Specific line from a file?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|