reading lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reading lines
# 1  
Old 04-21-2010
reading lines

I want a script that while it read the lines in the file below,it will check if the second variable is greater or equal 10.if less delete the line


tom|2
john|5
simms|23
reed|30
paul|11



After running scripts i should get

simms|23
reed|30
paul|11
# 2  
Old 04-21-2010
Code:
 
awk -F"|" '$2 > 10 && $3==1 { print }' input_file


Last edited by panyam; 04-21-2010 at 01:13 PM..
# 3  
Old 04-21-2010
Thanks

what if i want to print only the one with $2 >10 and $3=1
like
tom|2|1
john|5|1
simms|23|1
reed|30|0
paul|11|0

and get results

simms|23|1
# 4  
Old 04-21-2010
Quote:
Originally Posted by tomjones
Thanks

what if i want to print only the one with $2 >10 and $3=1
like
tom|2|1
john|5|1
simms|23|1
reed|30|0
paul|11|0

and get results

simms|23|1
check , my previous updated post.
# 5  
Old 04-21-2010
As panyam mention ... in awk you have to use only &&
Code:
awk -F"|" '$2>10 && $3==1 {print}' input_file

# 6  
Old 04-21-2010
Thank you so much
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading multiple lines with condition

Hi guys, I need to read following lines and put them in same row …. text: Abcd5437_XYA0_B1_WXYZ_BE 99:00:14:42:55:01:d4:22 99:00:14:42:70:01:d4:22 99:00:14:42:55:03:a0:22 99:00:14:42:70:03:a0:22 ... (4 Replies)
Discussion started by: dc@bos
4 Replies

2. Shell Programming and Scripting

Csh reading lines

Hi, I have been trying to do a little script in Csh, to classify some information of a text document. My problem appears when i have to calssificate two parts of the same line into different variables, for example in the document appears something like that: ID NAME 999999,Michel... (1 Reply)
Discussion started by: losbirras
1 Replies

3. Shell Programming and Scripting

Reading in two lines at once from a text file

Hello everyone, I have thought about this for quite some time and know what I want to do but am having some trouble at it. I have a text file filled with numbers like this, there are more in the file obviously. Each number is separated by a space. 1 3 2 4 5 1 -1 1 0 -1 5The idea is... (7 Replies)
Discussion started by: tastybrownies
7 Replies

4. Shell Programming and Scripting

Reading two lines in a while loop and combining the lines

Dear all, I have a file like this: imput scaffold_0 1 scaffold_0 10000 scaffold_0 20000 scaffold_0 25000 scaffold_1 1 scaffold_1 10000 scaffold_1 20000 scaffold_1 23283 and I want the output like this: scaffold_0 1 scaffold_0 10000 scaffold_0 10000 scaffold_0 20000... (6 Replies)
Discussion started by: valente
6 Replies

5. Shell Programming and Scripting

Regarding reading lines into a new file

Hi all, I jut use a loop to read lines from the user and redirect it to a file. echo "Enter the line" while read -r LINE do echo $LINE >> FILE if ;then break fi done input app... (1 Reply)
Discussion started by: Ananthdoss
1 Replies

6. Shell Programming and Scripting

skip lines while reading a file

Hi Experts, I am tryin to read a file and while doing so i need to skip the lines which start with a hash (#) char. I thought of using a goto command but a lot of guys on this site say its not the good way to program. Moreover I am using a ksh shell which deos not support goto command. ... (4 Replies)
Discussion started by: bankimmehta
4 Replies

7. Shell Programming and Scripting

reading lines

Hi all, I have a file whose content I need to read and get the 3rd line .. ex: one two three What I need is to read a content of third line of this file and print first three characters ... I could print first three characters with "head -c 3" if I could get the content of the third line... (4 Replies)
Discussion started by: c0mrade
4 Replies

8. UNIX for Dummies Questions & Answers

skip reading certain lines in a file

How can I exclude reading lines in a file that contains the following: filesystem:/home/pach/liv_patches 128005120 88456640 37270758 71% /home/patches That is, all lines that contain and begins with filesystem: should not be processed/read from a file (5 Replies)
Discussion started by: paulsew
5 Replies

9. Shell Programming and Scripting

Reading multiple lines as single

Hi, Is it possible to read every 2 lines as single record, I have a file like below, ~CZK ~TSCHECHISCHE KRONE ~TSCHECH. REPUBLIK Dec 1 2005 12:00AM~ 10.840000~ ~DKK ~DAENISCHE KRONE ~DAENEMARK Dec 2 2005 12:00AM~ ... (9 Replies)
Discussion started by: braindrain
9 Replies

10. Shell Programming and Scripting

Reading lines within vi editor

Hi All, I need to read line by line from a file(created using vi editor) till end of the file and pass it to my own executables so that it will read first line and execute and then other and so on...Thanks The steps are like this; 1) read first line in file 2) execute the job with first line as... (2 Replies)
Discussion started by: asriva26
2 Replies
Login or Register to Ask a Question