generate new string from a text file

Hi,

I have a file and the content looks like this:

line1
line2
File #5 : found
'/u01/testing.txt'
line5
line6
line7
File #12 : found
'/u01/testabc.txt'
line10
line11

I want to write a bash script to give me the output:

The file 5 is '/u01/testing.txt'
The file 12 is '/u01/testabc.txt'

As I am new in shell script, can anyone tell me how to do this?

Thanks!!
Walter

try this

sed -n '/found/{p;n;p;}' filename | tr '\n' ' ' | sed -e 's/ : found/ is /g' -e 's/File/\nFile/g'
awk '/File #/{printf "%s %s is ",$1,$2;getline;print}' filename
sed -n '/File #/{N;s/ : found\n/ is /p;}' filename

Thanks!
It Works!

can you please give idea how you people are writing prog using sed and awk.
i tried several time and but failed.
please give me idea how start.

i read lot of stuff in sed and awk , even thu after seeing this i feel still i lag some where.

any help would be great full

Jacoden and Radouluv, you guys are really good at this stuff.

If you have a moment to break down the thought process behind some of your solutions, I know that many people would benefit.

Thanks

awk

awk '/File #/{printf "%s %s is ",$1,$2;getline;print}' filename
/File #/{printf "%s %s is ",$1,$2;

If the record matches the pattern "File #", print (formated without a trailing new line: "%s %s is ") fields #1 and 2 (default field separator - space* - is assumed), so in our case the first match returns:

File #5 is 
getline;print}

Read the next record (getline) and print it. So from:

File #5 : found
'/u01/testing.txt'

we get:

File #5 is '/u01/testing.txt'

sed

sed -n '/File #/{N;s/ : found\n/ is /p;}' filename
sed -n '/File #/{N;
  1. The -n option: suppress automatic printing of pattern space.
  2. If the current record/line matches the pattern "File #"...
  3. N; - Read/append the next line of input into the pattern space,
    so now, after the first match, our pattern space contains:
File #5 : found
'/u01/testing.txt'
s/ : found\n/ is /

In the pattern space: substitute the pattern ": found
" with " is ".

p;}

Print the current pattern space.

P.S. I modified my original sed version (a small fix).