Q1

Do some research on shell programming on the web You will probably realise
your mistakes.
(I am assuming you are using BASH - I am not sure of the syntax in other
shells)

Q2

Try awk. Read "NR" lines from second file (one with replacements), use the
string to modify $0
gawk may have a simpler/cleaner soln,. but it wont be compatible


On Sun, Jan 18, 2009 at 13:31, Prashant Batra <[email protected]>wrote:

>
> #$1 is the file in which contains text to be replaced
> #$2 is the file which contains the text with which it is to be replaced
>
> filename=$1
> pattern=$2
>
> lines=`wc -l $2|cut -d' ' -f1`
>
> for i in `seq 1 $lines`
> do
>
> replacewd=`head -$i $2 | tail -1`               #read line by line
> echo $replacewd
> head -$i $1 | tail -1 > temp                    #write each line $1 in temp
> file
> sed "s/2u/${replacewd}u/" temp >> output        #replace 2 and append
> the output in output file
>
> done
>
> This could be one of the solution...
> but its not very general
>
> cheers
> Prashant Batra
>
>
>
>
>
> On 1/18/09, Prashant Batra <[email protected]> wrote:
> > filename=$1
> > lines=`wc -l $filename|cut -d' ' -f1` #finds no of lines in the file
> > echo "no of lines in the file are $lines"
> > declare -a array[2]
> > for i in `seq 1 $lines`
> > do
> > echo $i
> > array=`head -$i $filename | tail -1`
> > echo $array
> > done
> >
> >
> > This could be helpful
> > but the problem is that the value of array does not persist outside the
> > loop.
> > hope someone else could provide the answer.
> >
> > On 1/18/09, Sharad Birmiwal <[email protected]> wrote:
> >>
> >> Hi,
> >>
> >> I'm not gonna fix any code but I'll help you with whatever I can..
> >>
> >>> I don't know how many lines are present in the file.
> >>
> >> use "wc -l" for this
> >>
> >>> Q2)
> >>>
> >>> I have the following content on a file.I need to replace '2' in each
> line
> >>> with a different value which are present in a file
> >>
> >> Looks like a complicated operation. It'll be better if you do it in
> >> perl or something :p
> >>
> >>
> >> Sharad
> >>
> >> >>
> >>
> >
>
> >
>


-- 
Lots o' Luv,
Phani Bhushan

Let not your sense of morals prevent you from doing what is right - Isaac
Asimov (Salvor Hardin in Foundation and Empire)

--~--~---------~--~----~------------~-------~--~----~
l...@iitd mailing list -- group http://groups.google.com/group/iitdlug
-~----------~----~----~----~------~----~------~--~---

Reply via email to