redhat linux 8
how can I get the following code to print a file without printing the same line twice;;;
when there are 12 lines (ex)
ex;
awk 'NR ==8{"date"|getline d; printf "%s\t%s%s\n", "(profile file)", $0, "("d")"}{print}' file1
i am looking at this from a dataprocessing angle and the answer for some unknown reason has totally escaped me! what I would like to say is that I know about redirection.. so if it is a mater of redirecting out input thats not a problem.. but if there is a way to make it work in this aprticular way I would like to know.. thanks!
anyone?!
thanks dudes! i just have one more question ! using awk to process a paragraph in file... am I going to get this result and have to use sort or is there an actual way around that!:rolleyes:
I think that I finally see what your problem is. It's not that you input file has duplicate lines that you want to suppress. Your awk script is outputing line 8 twice. At the end of your awk script, change {print} to NR!=8{print}
thanks ! it worked! this is incredible.. i didn't know that it was possible to piece together a command that way.. this is definitely a break through for me!
red hat linux 8.0
I tried this simple script no lucK
echo "read number:\c:"
read number
echo "read name:\c"
read name
NR == $num{"date"|getline d; printf "%s\t%s%s\n", "profile file", $0, d}NR!=$num{print}
.......
run_file!
awk -f won't work even when I change the script..
and awk 'NR == $num.............. wont work either and the error message says taht fild Zero is name of script file.. please help[!!!!
Remember, variable's reference can't be prefixed with $ unless they are position variables like $0~$NF.
Ygor is right. However, you didn't modify your variable reference, so you failed.
Just skip the $, use "num".
By the way, when you want to print patterned line without twice display, just improve your structure like me.
[root@home root]# cat myawk8
#!/bin/gawk
{
if(NR==num){
"date"|getline d;
printf "%s\t%s%s\n","profile file",$0,d
next
}
print
}
[root@home root]# cat mydata
hi, i am home_king from linuxsir.org.
2003-12-5 Bash it.
I am shell's administrator.
[root@home root]# num=2
[root@home root]# gawk -f myawk8 num=$num mydata
hi, i am home_king from linuxsir.org.
profile file 2003-12-5 Bash it.�� 4�� 16 01:44:50 CST 2004
I am shell's administrator.