Shell : eliminating zero values and printing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell : eliminating zero values and printing
# 1  
Old 01-22-2013
Shell : eliminating zero values and printing

I have a log file containing the below data and should have the output file as below. and the output file should not contain any 0 values.
Eg. It should not contain 0000000:0000000 in it.


input.txt
Code:
Media200.5.5.1     00010003:065D1202
Media100.5.5.2     7,588,666,067,931,543
Media100.5.5.3     0
Media200.5.5.4     1
Media200.5.5.5     4
Media200.5.6.1     00010002:065D1202
Media200.5.6.1     00000000:00000000
Media200.5.6.2     7,588,727,347,785,821
Media300.5.6.3     0
Media500.5.6.4     1
Media700.5.6.5     1
Media300.5.7.1     00010003:065D1202

output.txt
Code:
Media200.5.5.1 00010003:065D1202
Media200.5.6.1 00010002:065D1202
Media300.5.7.1 00010003:065D1202

Could anyone please help with shell script for the above ...

Last edited by scriptscript; 01-22-2013 at 11:03 AM..
# 2  
Old 01-22-2013
2nd condition?

Is there an additional condition?
that the line contain a 17-character string, as in
Code:
xxxxxxxx:xxxxxxxx

That seems to be how you eliminate the 2nd-5th lines
# 3  
Old 01-22-2013
There is no such condition. But the only thing is the final output should not contain
Code:
00000000:00000000 values

# 4  
Old 01-22-2013
So, output should be ?:
Code:
Media200.5.5.1     00010003:065D1202
Media100.5.5.2     7,588,666,067,931,543
Media100.5.5.3     0
Media200.5.5.4     1
Media200.5.5.5     4
Media200.5.6.1     00010002:065D1202
Media200.5.6.2     7,588,727,347,785,821
Media300.5.6.3     0
Media500.5.6.4     1
Media700.5.6.5     1
Media300.5.7.1     00010003:065D1202

eliminating the one entry with 00000000:00000000
# 5  
Old 01-22-2013
no sir...

The output should be as mentioned above..

Code:
Media200.5.5.1 00010003:065D1202
Media200.5.6.1 00010002:065D1202
Media300.5.7.1 00010003:065D1202

I need to have the o/p as shown above.. contains only the non zero values in the above format. And this values eg 00010003:065D1202 will be change other than zeros.
# 6  
Old 01-22-2013
How about?
Code:
awk '/:/&&!/00000000:00000000/' log_file

# 7  
Old 01-23-2013
Please try this, it will work

Code:
grep ":" $file | sed "/00000000:00000000/d"


Last edited by Scrutinizer; 01-23-2013 at 03:43 AM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing null values in awk

Hi, I have a csv file with given details abc.txt 123,ra,point,,there 232,ba,points,home,pheer I want to get those values and store them in different variables: Code: while read line do echo $line |awk -F"," '{print $1" "$2" "$3" "$4" "$5"}'|read dbt_acct val_dt crncy AMT... (11 Replies)
Discussion started by: rahulsk
11 Replies

2. Shell Programming and Scripting

Printing $values using awk

Hi All I had requirement where I need to re-order columns in a file by using a control file. here is the ctrl file c1 c2 c3 source file c3 | c1 | c2 a | b| c I should create output file based on the ctrl file columns o/p should look like this c1 | c2 | c3 b| c|a I wrote some... (9 Replies)
Discussion started by: gvkumar25
9 Replies

3. Programming

Printing values from a class

I have a class and want to print values in MOD using L = new Layer* ; How can I print the values in MOD using this object L??? class Layer { public : Model* MODP; Model* MODS; (1 Reply)
Discussion started by: kristinu
1 Replies

4. UNIX for Dummies Questions & Answers

Eliminating entries based on relative values

I have posted this before but did not get much feedback. So I will try again. I need to remove sequences from a file based on values listed on a second file. The sequences file looks like this: Sequences.txt >Sample1 Freq 59 ggatatgatgatgaactggt >Sample1 Freq 54 ggatatgatgttgaactggt... (4 Replies)
Discussion started by: Xterra
4 Replies

5. Programming

Printing float values in C

Hi, I have small problem to print float value in the fallowing code float Cx, W,f=250000, Cr=92.00,pi=3.14; W=2*pi*f; Cx = 1/W.Cr; //Cx value will be come around like 7.07E-9. printf("capacitance value: %.10f",Cx); I am trying to print Cx value using above code but it was not... (3 Replies)
Discussion started by: veerubiji
3 Replies

6. Shell Programming and Scripting

printing two values with TAB in between

Dear friends, I want to print variables' values in certain format where space between two values of variables is "a tab" I tried where I provided "tab" between two varibales. But when it print values on screen its giving me output without spaces in two values. Request you to help me in... (7 Replies)
Discussion started by: anushree.a
7 Replies

7. UNIX for Advanced & Expert Users

Printing defaulted values

I have written a phyton script that accepts command line arguments. I am setting defaults for some of them if the user does not specify them. However I want to print the user values and the defaulted values seperately. However, once I set the default values, then I cannot use if... (0 Replies)
Discussion started by: kristinu
0 Replies

8. Shell Programming and Scripting

printf in bash shell not printing negative values

hi i am using printf in a script and it is not printing negative values..i have to use printf to get rid of the newline..here is my code: fin=`echo $a - $b | bc` printf "${fin}," >> test these statements are in a loop. here is what i get when i try to subtract 4 from 8: ./scr1: line... (2 Replies)
Discussion started by: npatwardhan
2 Replies

9. Shell Programming and Scripting

UrgentPlease: compare 1 value with file values eliminating special characters

Hi All, I have file i have values like ---- 112 113 109 112 109 I have another file cat supplierDetails.txt ------------------------- 112|MIMUS|krishnaveni@google.com 113|MIMIRE|krishnaveni@google.com 114|MIMCHN|krishnaveni@google.com 115|CEL|krishnaveni@google.com... (10 Replies)
Discussion started by: kittusri9
10 Replies

10. Programming

printing all array values using dbx 7.2.1

how do we print the entire contents of arrays in dbx ? Ive tried using print x to print values 1 to 5 of the array x, however dbx complains and doesnt allow this help is much appreciated (1 Reply)
Discussion started by: JamesGoh
1 Replies
Login or Register to Ask a Question