Search Results

Search: Posts Made By: ctrld
3,155
Posted By ctrld
Count pattern line by line
I have a file like below with more than 30,000 lines:

Someword "mypattern blah blah mypattern blah mypattern blah "
Someotherword "mypattern blah blah mypattern blah mypattern blah"
Someword...
2,298
Posted By ctrld
Perl script with lock to execute only once in a day
Hi,

I am new to perl and have a script to which i want to ensure that no matter how many ever times i execute the script it should execute only once per day. Cronjob is not a safe method as I...
2,743
Posted By ctrld
Thank you for confirming :)
Thank you for confirming :)
2,743
Posted By ctrld
I am extremely sorry! I think I was late to note...
I am extremely sorry! I think I was late to note that I wanted reverse of what this code is doing now;

if awk '/pattern/ {T[$2]++}; END {for (t in T) if (T[t] > 1) exit 1}' file[12]
then echo...
2,743
Posted By ctrld
Awesome and super quick! :) I just made a...
Awesome and super quick! :)

I just made a small adjustment for better look. Please correct me if I am wrong :

awk '/pattern/ {T[$2]++}; END {for (t in T) if (T[t] > 1){print "Second column is...
2,743
Posted By ctrld
Awk/bash one liner replacement for a if condition
Hi.

I wrote this small bash script, i want to compare second column from file1 with file2 if a pattern matches. Files are small and I am sure that pattern occurs only once. I think this can be...
3,412
Posted By ctrld
How to provide read access to root crontab?
Hi,

Is there any safe method to provide read access to root's crontab to another user? Just read no other permissions.
847
Posted By ctrld
Python for monitoring apache and restarting if down
Are there any existing python module for service monitoring? For example apache service?
877
Posted By ctrld
Break in for loop
in my python script i have loop like below:

for item in itemlist:
if <condition>:
<code>
else:
<code>
if <condition>:
if <condition>:
...
955
Posted By ctrld
Thanks all. The first solution probably was for...
Thanks all. The first solution probably was for row sum. Second and Third perfectly worked. Third solution is more crisp and clear, I liked it the most. Thanks a ton guys.
955
Posted By ctrld
Column sum
I have a text file in below format

First Column Header |Second Column Header| Third Column Header| Fourth Column Header| Fifth Column Header
DATA1| 1.4|22.80| 6.6|6.55
DATA2| 1.4|NA| 6.8|6.83...
1,163
Posted By ctrld
Thanks Ravinder and Don, both solutions worked...
Thanks Ravinder and Don, both solutions worked perfect. All are equally good. Thanks once again for your quick response.
1,163
Posted By ctrld
Replace text in columns
I have two files in below formats:

cat file1
abc|abcd|10|1020
10|xyz|1010|1020
abc|abcd|10|1020
10|xyz|1010|1020

cat file2
abc|abcd|10|1020
11|xyz|1010|1020
abc|abcd|12|1020...
5,155
Posted By ctrld
This one works perfect. awk '{if((Q=100-(($2...
This one works perfect.

awk '{if((Q=100-(($2 * 100)/$3)) > 5){print Q, $0}}' input.txt
45.7711 ITEM1 10.9 20.1
10.828 ITEM3 14 15.7
60.4743 ITEM5 20 50.6

Seems like awk is not considering if...
5,155
Posted By ctrld
This one works perfect. awk '{if((Q=100-(($2...
This one works perfect.

awk '{if((Q=100-(($2 * 100)/$3)) > 5){print Q, $0}}' input.txt
45.7711 ITEM1 10.9 20.1
10.828 ITEM3 14 15.7
60.4743 ITEM5 20 50.6

Seems like awk is not considering if...
5,155
Posted By ctrld
Appreciate your quick help. I got following...
Appreciate your quick help. I got following output:

awk '{if((Q=100-(($2 * 100)/$3)) > 5 || Q >= -5){print Q, $0}}' input.txt
45.7711 ITEM1 10.9 20.1
3.33333 ITEM2 11.6 12
10.828 ITEM3 14 15.7...
5,155
Posted By ctrld
Calculate percentage difference between two columns
I have a input text file in this format:

ITEM1 10.9 20.1
ITEM2 11.6 12
ITEM3 14 15.7
ITEM5 20 50.6
ITEM6 25 23.6

I want to print those lines which have more than 5% difference [negative or...
1,689
Posted By ctrld
Thanks Aia. This is an elegant solution to my...
Thanks Aia. This is an elegant solution to my problem.
1,689
Posted By ctrld
Thanks Rudic. If I create a function I need...
Thanks Rudic.

If I create a function I need to return several values. I think that would not look nice. Probably I would do that only as calling the function with the array also would be just like...
1,689
Posted By ctrld
cat input.txt ...
cat input.txt

element1=element2=abc=def=zyz=12345=6789=100000
element2=element1=abc=def=zyz=12345=6789=100000
element3=element4=abc=def=zyz=12345=6789=100000

input.txt is just a delimited...
1,689
Posted By ctrld
Python passing multiple parameters to functions
Hi,

I am a beginner in python programming. In my python script have a main function which calls several other functions. The main function gets its input by reading lines from a input text file. I...
2,062
Posted By ctrld
Thanks wisecracker!!
Thanks wisecracker!!
2,062
Posted By ctrld
Sweet!! I thought about an exit function but it...
Sweet!! I thought about an exit function but it was not this neat.. this is cool..
2,062
Posted By ctrld
Thanks wisecracker.. The sys module not...
Thanks wisecracker..

The sys module not needed for 2.6 above is a new learning for me.

I am already having a KeyboardInterrupt check in my code.

What I am trying to achieve here is to...
2,062
Posted By ctrld
If condition after raw input in python
Hi,

I have a python script which is completely interactive. I have almost 10+ raw input statements like below which are collected from user one by one.

req_number = raw_input("Please enter...
Showing results 1 to 25 of 66

 
All times are GMT -4. The time now is 09:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy