hi all,
Im using the following script to select alternative lines from a file.
cat -n <filename> | awk '{ if ($1%2 =0) print $0)
its output contains the line number but i dont want it, Anyone help me
in this regard
Thanks & Regards,
Gopi Krishnan
Thanks & Regards,
Gopi Krishnan
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
>>hi all,
>> Im using the following script to select alternative lines from a file.
>>cat -n <filename> | awk '{ if ($1%2 =0) print $0)
>> its output contains the line number but i dont want it, Anyone help me
>>in this regard
> awk 'NR % 2 == 0 { print }' FILENAME
awk 'NR%2' file
and this for even:
awk '(NR+1)%2' file
Regards,
Ed.
>>>hi all,
>>> Im using the following script to select alternative lines from a file.
>>>cat -n <filename> | awk '{ if ($1%2 =0) print $0)
>>> its output contains the line number but i dont want it, Anyone help me
>>>in this regard
>> awk 'NR % 2 == 0 { print }' FILENAME
> No need for the "{ print }" as that's the default action.
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
>>>>hi all,
>>>>Im using the following script to select alternative lines from a file.
>>>>cat -n <filename> | awk '{ if ($1%2 =0) print $0)
>>>>its output contains the line number but i dont want it, Anyone help me
>>>>in this regard
>>>awk 'NR % 2 == 0 { print }' FILENAME
>>No need for the "{ print }" as that's the default action.
> It's not necessary in this limited script, but it's more
> understandable, and easier to deal with when modifying the script
> later.
Ed.
>>>>awk 'NR % 2 == 0 { print }' FILENAME
>>>No need for the "{ print }" as that's the default action.
>> It's not necessary in this limited script, but it's more
>> understandable, and easier to deal with when modifying the script
>> later.
> Then you should make it "{ print $0 }" for those reasons.
When you are familiar with them, by all means use them; I don'tQuote:> Personally I think it's more useful for people to understand and
> take advantage of the default behaviors, especially with small,
> throwaway scripts.
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
To output even numbered lines
awk '!(NR%2)' filename # parentheses necessary since ! has precedence over %
To output odd numbered lines
awk 'NR%2' filename # parentheses necessary since ! has precedence over %
Dan Mercer
--
I told my kids, "Someday, you'll have kids of your own." One of them said,
"So will you."
-- Rodney Dangerfield
> When you are familiar with them, by all means use them; I don't
> think they're appropriate for someone who has to ask about how to
> accomplish a task in the first place. When the experts get into a
> "Mine's shorter than yours!" battle, that's different.
Ed.
>> When you are familiar with them, by all means use them; I don't
>> think they're appropriate for someone who has to ask about how to
>> accomplish a task in the first place. When the experts get into a
>> "Mine's shorter than yours!" battle, that's different.
> This isn't about brevity. I'm glad the experts I know in various areas
> showed me how to do things the way they do rather than the way they
> think is good enough for me. At least, I hope they did! It's better to
> learn the right way first rather than have to break a bad habit later.
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
1. select line from file, and then the next line a week later
Let's say I have a file of 5 email addresses. What if I wanted to email
one person on the list, in sequence, every friday. So on the first
friday, I would email the first person. The following friday I would
email the second person, and so on....
Now I could cron it for friday, but how can I get the script to grab
line one the first time I run it, then grab line 2 the next time I run
it. Is this even possible?
I don't think 'case' can do this for me. I am guessing awk might be
able to, but I am no good at awk.
2. ipfwadm: how can I accept random ports for ftp data connections ?
3. How can I prepend comments into selected lines of a data file?
4. "inconsistent soname" errors from /sbin/ldconfig
5. selecting duplicate lines in file
6. REPORT: Oak OTI-087 & Cheapo monitor working...almost
7. randomly select a line from a file
9. Selecting a random line from a text file
10. How do you remove selected lines from file?
11. select a specific line from an ascii file
12. deleting selected lines in a file
13. perl: copy selected line from one file to another