1751969 Members
4808 Online
108783 Solutions
New Discussion юеВ

sed&awk

 
ehab_2
Occasional Contributor

sed&awk

How can make ignore processing pf previuos record .

If y[i]=$0

for (i=1;i<=NR;i++)
{
print y[i]
}

The out put will be :
line1
line1
line2
line1
line2
line3

I want it :
line1
line2
line3
5 REPLIES 5
Christian Gebhardt
Honored Contributor

Re: sed&awk

Hi
command sort and uniq

#cat file
line1
line1
line2
line1
line2
line3

#cat file | sort | uniq

line1
line2
line3

Chris
Jean-Louis Phelix
Honored Contributor

Re: sed&awk

hi,

"sort -u file" will do it, but you will lost the initial order.

regards,

Jean-Louis
It works for me (┬й Bill McNAMARA ...)
T G Manikandan
Honored Contributor

Re: sed&awk

#sort -u
Oren_3
Occasional Contributor

Re: sed&awk

If the original order of the files is important to you, you can use a temp file containing the already printed files.

it should look:
tmp_file=/tmp/tmpfile.$$

if y[i]=$0
for (i=0,i<=NR;i++)
{
if (cat tmp_file|grep y[i]|wl -l == 0
{
echo y[i] >> tmp_file
printf(y[i])
}
}
\rm tmp_file
H.Merijn Brand (procura
Honored Contributor

Re: sed&awk

# perl -ne '$x{$_}++ or print' file

prints unique lines keeping original order
Enjoy, Have FUN! H.Merijn