print ODD lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting print ODD lines
# 1  
Old 10-29-2010
print ODD lines

i want to print ODD lines like first ,third then fifth and so on


Code:
234,567,ABC,KJL
234,565,ABD,KJL
234,568,ABE,KJL
234,560,ABF,KJL
234,563,ABG,KJL
234,562,ABH,KJL

O/P will be like
Code:
234,567,ABC,KJL  ----->first liine
234,568,ABE,KJL  ----->third line
234,563,ABG,KJL  ----->fifth line and so on.....

Please help me
This User Gave Thanks to aaysa123 For This Post:
# 2  
Old 10-29-2010
Try...
Code:
awk 'NR%2' file1

# 3  
Old 10-29-2010
Hi,
Code:
sed -n '1~2 p' infile

Regards,
Birei
# 4  
Old 10-29-2010
@birei

Could you pls tel how this works.. 1~2 p
# 5  
Old 10-29-2010
Code:
perl -ne 'print if($.%2)' file

# 6  
Old 10-29-2010
Hi,

Beginning in first line, prints one each two: First, third, fifth, etc.

Regards,
Birei
# 7  
Old 10-29-2010
Note: ~ is GNU sed only. Alternatively use:
Code:
sed 'n;d' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk with sed to combine lines and remove specific odd # pattern from line

In the awk piped to sed below I am trying to format file by removing the odd xxxx_digits and whitespace after, then move the even xxxx_digit to the line above it and add a space between them. There may be multiple lines in file but they are in the same format. The Filename_ID line is the last line... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Find to delete lines with pattern and even or odd number

In the below directory I am trying to delete all lines with a .bam extention that have the pattern IonCode_ followed by an even number. I am also trying to delete all lines with a .fastq extention that have the pattern IonCode_ followed by an odd number. I was going to use find but can see all... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

Select / Print odd-even elements of an array

Hello experts, I wish to print the contents of odd-even numbered indices of an array. The problem statement is as follows : 1. The first line contains an integer, (the number of test cases). 2. Each line of the subsequent lines containing a string. Example: 2 Haider Bash ... (4 Replies)
Discussion started by: H squared
4 Replies

4. UNIX for Dummies Questions & Answers

Replace character in odd or even lines

Hello, I'm here again asking for your precious help. I'm writing some code to convert csv files to html. I want to highlight header and also I want to have rows with alternate colors. So far this is my work###Let's format first line only with some color cat $fileIN".tmp1" | sed '1... (7 Replies)
Discussion started by: emare
7 Replies

5. Shell Programming and Scripting

awk print odd values

value=$(some command) for all in `echo $value` do awk checks each value (all) to see if it is a odd number. if so, prints the value done sounds easy enough but i've been unable to find anything on google. (2 Replies)
Discussion started by: SkySmart
2 Replies

6. Shell Programming and Scripting

Sum product of even/odd lines

Hi, I have a text file like this 6.0000E-02 0.00000E+00 0.0000 0.00000E+00 0.0000 7.0000E-02 5.00000E-10 1.0000 5.00000E-10 1.0000 8.0000E-02 3.00000E-09 0.4082 3.00000E-09 0.4082 9.0000E-02 3.50000E-09 0.3780 3.50000E-09 0.3780 1.0000E-01 1.00000E-09... (2 Replies)
Discussion started by: f_o_555
2 Replies

7. Shell Programming and Scripting

Insert at the beginning of odd lines

Hello people, I am trying with sed to insert some text at the beginning of each odd line of a file but no luck. Can you please help. Awk is also suitable but I am not very familiar with it. Thank you in advance for any help. (7 Replies)
Discussion started by: drbiloukos
7 Replies

8. Shell Programming and Scripting

How to search for pattern in odd lines?

Hi friends, I am looking for sed command/script that would search for a given fixed pattern on odd lines and then if it matches, prints the matching pattern and the next line. For example, in the example below, i am looking for pattern 0 and 1011 on odd lines. ########## start of example file... (10 Replies)
Discussion started by: kaaliakahn
10 Replies

9. Shell Programming and Scripting

odd problem in read lines from file

Hi, I wrote a small program to read lines from a file and count the lines. The program is as below: filename=$1 count=0 cat $filename | while read -r line do printf "%5d:%s\n" $count "$line" count=$((count + 1)) done echo " $count " After I run the program, the result is... (4 Replies)
Discussion started by: jianma
4 Replies

10. Shell Programming and Scripting

print lines AFTER lines cointaining a regexp (or print every first and fourth line)

Hi all, This should be very easy but I can't figure it out... I have a file that looks like this: @SRR057408.1 FW8Y5CK02R652T length=34 AGCAGTGGTATCAACGCAGAGTAAGCAGTGGTAT +SRR057408.1 FW8Y5CK02R652T length=34 FIIHFF6666?=:88@@@BBD:::?@ABBAAA>8 @SRR057408.2 FW8Y5CK02TBMHV length=52... (1 Reply)
Discussion started by: kmkocot
1 Replies
Login or Register to Ask a Question