Discussion: awk help-simple doubt
Afficher un message
Vieux 15/03/2008, 22h29   #2
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk -simple doubt

varkey@changingideas.com wrote:

> hey guys,
>
> i hav got two files as follows
>
> file1.txt
>
> bss:1
> bss:2
> bss:3
> bss:4
> bss:5
>
>
> file2.txt
> db1
> db2
> db3
> db4
> db5
>
>
> i m reading the first file using a for loop


Using something like

for line in `cat file1.txt`

I suppose.

> so when i read the first line in file1.txt (ie bss:1) i need to get
> the corresponding one in file2 (ie. db1)
>
> like wise till db5 when i reads bss:5
>
> how can i implemnt it usig an awk with in a for loop?


You can use awk without any loop at all (assuming your input lines have no
spaces in them):

$ paste file1.txt file2.txt | awk '{print $1,$2}'

or, if you absolutely want to use a loop

$ paste file1.txt file2.txt | while read line1 line2; do
....

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
  Réponse avec citation
 
Page generated in 0,04830 seconds with 9 queries