help on a basic example

hi,
in a text file i have listed some file names,
it look like this

AAAA1
AAAA2
AAAA3
BBBBB1
AAAA4
BBBBB2
BBBBB3
AAAA5
AAAA6
BBBBB4

i want to make some operations on the files with name AAAAAx
which is listed just before files with name BBBBBx

that is: i want to select AAAA3, AAAA4, AAAA6 from the above list do some operations on them,

how can i achive this using shell script?
(preferably without using awk)

for i in `cat filelist`
do
## $i has the name of files - do whatever you want to do here.
## Use echo $i to find what you are getting here.
done

try this:

sed -n "/^A/p" source_file >filename
for var in `cat filename`; do
# Do what ever
done
sed -n "N;/\nBBBBB/s/\n.*$//p" file

That is almost always the wrong way to read a file. Apart from the useless use of cat (UUOC), it will break if any lines contain spaces.

If temp is the filename which contains the data, please use the below:

sed -n '/BBBBB./{g;1!p;};h' temp |uniq

Originally Posted by Deal_NoDeal
for i in `cat filelist`

That is almost always the wrong way to read a file. Apart from the useless use of cat (UUOC), it will break if any lines contain spaces.

i want to do some operations in a for loop what else i can use
instead of for i in `cat filelist` not to break lines which contain spaces

while read str
do
...
done < file

Use the while loop method suggested by anbu above. That takes care of spaces too.