help on a basic example


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help on a basic example
# 1  
Old 03-01-2007
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)
# 2  
Old 03-01-2007
Quote:
Originally Posted by gfhgfnhhn
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
# 3  
Old 03-01-2007
Quote:
Originally Posted by gfhgfnhhn
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)
try this:
Code:
sed -n "/^A/p" source_file >filename
for var in `cat filename`; do
# Do what ever
done

# 4  
Old 03-01-2007
Code:
sed -n "N;/\nBBBBB/s/\n.*$//p" file

# 5  
Old 03-01-2007
Quote:
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.

Quote:
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
# 6  
Old 03-01-2007
If temp is the filename which contains the data, please use the below:

sed -n '/BBBBB./{g;1!p;};h' temp |uniq
# 7  
Old 03-05-2007
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
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. What is on Your Mind?

Vs basic

There isn't much of a relation between 80's BASIC and today's BASIC. A lot of languages seem similar. The BASIC I worked with was Dartmouth or VSBASIC. Now existing as ATARI BASIC. PERL and JULIA look appealing, it would be nice if there where a program like VSBASIC. 80's... (7 Replies)
Discussion started by: teak
7 Replies

2. UNIX for Dummies Questions & Answers

Basic help

Hi , I need to know the difference between $((command)) and $(command) and $(($(command))). "" and '' and ``. I have tried searching the help files but cant able to find this. Could you let me knoq about any document. Thanks (4 Replies)
Discussion started by: Raj999
4 Replies

3. Solaris

Basic - how do I?

How do I use ls and grep together to count a certain number of files in a directory? -Thanks (1 Reply)
Discussion started by: secno
1 Replies

4. HP-UX

to know the basic

Hi, Good morning I want to install HP-Unix in my PC. I already have windows XP home edition in my PC. I do not want remove XP,But I need HP-Unix in the same system. Is it posssible? If it is what is the name and version of HP-Unix cd? Where can I get the CD to install. I have... (4 Replies)
Discussion started by: nandhini
4 Replies

5. UNIX for Dummies Questions & Answers

Need some basic help

Hi everyone, I need some help! I know that this is a very simple little problem but I seem to be stuck. I was just wondering if you could show me the right way. I basicly have to write a single line of commands (using piping) to do the following: From the file data.txt, select all of the... (2 Replies)
Discussion started by: itk
2 Replies

6. HP-UX

Bt-basic

Hi Guys, I very new to bt-basic even I got 8 years experience on UNIX. I searched through google about bt-basic but nothing really give me solid documentation. Anybody have documentation or manual for this bt-basic? Pls help me (2 Replies)
Discussion started by: shahru
2 Replies

7. What is on Your Mind?

Basic...

hi, I am pretty new both to unix and this forum, can anyone help me to give shortcuts to my commands... eg:- instead of "cd /usr/bin" i want to to give " bin " and get to that path. I'm using HP-UX 11.0 abey (2 Replies)
Discussion started by: abey
2 Replies

8. UNIX for Dummies Questions & Answers

Basic

hi, I am pretty new both to unix and this forum, can anyone help me to give shortcuts to my commands... eg:- instead of "cd /usr/bin" i want to to give " bin " and get to that path. I'm using HP-UX 11.0 abey (2 Replies)
Discussion started by: abey
2 Replies
Login or Register to Ask a Question