Visit Our UNIX and Linux User Community

print out result from data file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting print out result from data file
# 1  
Old 01-30-2008
print out result from data file

i got a data file which contains all the pid,ppid,user,command,pcpu,start_time,status. I wanted to display out the pcpu which is greater than 0.

i uses awk'{if($5 > 0){print}}' filename.txt but is printing out result which not i wanted. Is there any way which i can print out those pcpu which is greater than 0?
# 2  
Old 01-30-2008
Both of them should work

awk '{if($5 > 0){print}}' file
awk '$5 > 0 {print}' file

Could you please put some sample data of your file.
# 3  
Old 01-30-2008
Dear thms sum,

can u plz provide an example of ur need?

# 4  
Old 01-30-2008
i have attached a sample of my data file. i would like to only display cpu which is above 0 from the data file. how can go with awk to make it display?
# 5  
Old 01-30-2008
awk '$(NF-2)>0' input

# 6  
Old 01-30-2008
thanks radoulov!!! its works!!! but can u explain y got to NF-2?
# 7  
Old 01-30-2008
Some CMD column values contain spaces so for Awk (with default FS) %CPU is not always $5,
therefore as long as START and STAT values don't contain spaces $(NF-2)
(the number of fields of the crrent record - 2) will work Smilie

Previous Thread | Next Thread
Test Your Knowledge in Computers #189
Difficulty: Easy
The boolean data type in Python is immutable.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To get or print specific value in result

i am executing below code to achive my result, but for second row the value is not coming it should come URL like other two . url start with http:// and end with .xhtml cat FILE | grep 'Test failed' | awk -F',' '{print $3,$8,$12}' INPUT 1517679173303,84,SKILLED LANGUAGE - ENTER... (11 Replies)
Discussion started by: mirwasim
11 Replies

2. Shell Programming and Scripting

Compare 2 columns from the same file and print a value depending on the result

Hello Unix gurus, I have a file with this format (example values): label1 1 0 label2 1 0 label3 0.4 0.6 label4 0.5 0.5 label5 0.1 0.9 label6 0.9 0.1 in which: column 1 is a row label column 2 and 3 are values I would like to do a simple operation on this table and get the... (8 Replies)
Discussion started by: ksennin
8 Replies

3. Shell Programming and Scripting

awk parse result that match data from file

i run command that return this result,example : gigabitethernet2/2/4:NotPresent, gigabitethernet2/1/17:UP, gigabitethernet2/1/10:UP, gigabitethernet2/1/5:UP, gigabitethernet2/1/9:UP, gigabitethernet2/1/36:DOWN, gigabitethernet2/1/33:DOWN, gigabitethernet2/1/8:UP,... (19 Replies)
Discussion started by: wanttolearn1
19 Replies

4. UNIX for Dummies Questions & Answers

Print result of mv -n

I am trying to move files which donot have same filename using find /Users/ParijatMac/desktop/unix/new_dir -type f -mmin +"$HRS" -exec mv -n "{}" /Users/ParijatMac/desktop/unix/old_dir \; -print but i am getting all filenames including the ones with duplicate names.Please help me to sort... (5 Replies)
Discussion started by: parijat guh
5 Replies

5. Shell Programming and Scripting

Use PYTHON to collect data weather and print in new file

Hi all, i have a task to do with Python and because i'm a beginner on it i would like your help on this. Create a python script that: Every hour collect the Temperature (e.g. 29C) and Current Condition (e.g. Clear) from this website Create a CSV... (0 Replies)
Discussion started by: ragaga123
0 Replies

6. Shell Programming and Scripting

How to combine data from 2 file ? How to print ?

Dear friends, I am just trying to print data from 2 file,namely file_1.txt and file_1.dat (specific column of ROW 1) file_1.txt 12 13 14 15 99 AMC 69 36 89 12 13 14 15 99 AMC 69 84 -12 12 13 14 ... (6 Replies)
Discussion started by: nex_asp
6 Replies

7. Shell Programming and Scripting

Compare a file with all others then print off data

my script so far nawk -F, 'NR==FNR{a++;next} a{b++} END{for(i in b){if(b-1){print i";\t\t"b}else{print "NEW:"i";\t\t1"} } }' OFS=, 20111228.csv *.csv | sort NE:221478,SHELF:13,SLOT:4; 2 NE:221726,SHELF:8,SLOT:1; 2 NE:222318,SHELF:14,SLOT:1; 9... (20 Replies)
Discussion started by: llcooljatt
20 Replies

8. Shell Programming and Scripting

Compare and print out data only appear in file 1 problem

Below is the data content of file_1 and file_2: file_1 >sample_1 FKGJGPOPOPOQA ASDADWEEWERE ASDAWEWQWRW ASDASDASDASDD file_2 >sample_1 DRTOWPFPOPOQA ASDADWEEASDF ASDADRTYWRW ASDASDASDASDD I got try the following perl script. Unfortunately, it can't give my desired output result... (7 Replies)
Discussion started by: patrick87
7 Replies

9. UNIX for Advanced & Expert Users

How to print data between 2 lines in a file

i want to print the data between two line numbers in file to another file. which command should i use i tried sed command . i am storing the line numbers in two variables say L1,L2. but $L1 and $L2 are not working in sed command. is there any other command to do this reply soon (5 Replies)
Discussion started by: kamesh83
5 Replies

10. Shell Programming and Scripting

print a function result in new file

Hi, i have a function which return a variable . serach ( paramatere) when i excute this function i get the result in the shell, i want to print this result in a file by calling just the function. how can i do it.. the code example is like that: search ( ) { .. } the call... (0 Replies)
Discussion started by: kamel.seg
0 Replies

Featured Tech Videos