Search Results

Search: Posts Made By: mukulverma2408
5,033
Posted By RudiC
For the fun of it; the (admitted lengthy)...
For the fun of it; the (admitted lengthy) "command substitution" finds the last line prior to the date/time given in DT1 on which sed needs to quit:
DT1="Jan 19 21:10:00"
sed "/$(echo "$DT1" | cut...
5,033
Posted By Chubler_XL
That looks like a good approach. You could...
That looks like a good approach.

You could get some more efficiency by not calling the date external on each input line and using bash to convert the date time to an mmddHHMMSS number for direct...
1,575
Posted By MadeInGermany
Because arguments are passed as strings, embedded...
Because arguments are passed as strings, embedded spaces are lost normally.
The original script makes an attempt to retain arguments with embedded special characters.
The improved original script...
1,575
Posted By Corona688
Looks extremely kludgy and pointlessly...
Looks extremely kludgy and pointlessly overcomplicated, I don't recommend it. This does the exact same thing without most of the nonsense and security holes.

#!/bin/sh

SCRIPT="$1"
U="$2"...
3,052
Posted By Don Cragun
This might be a suitable script to do what the...
This might be a suitable script to do what the comments in your code say it is trying to do:
#!/bin/bash
echo "This is a shell script to remove numbers divisible by 2 from an array"
if [ $# -gt 0...
8,168
Posted By Don Cragun
I don't think your code works as well as you...
I don't think your code works as well as you think it does. Try running your script again telling it that you want it to process 5 numbers and then enter the same number 5 times. Do you get the...
3,052
Posted By RudiC
You are - using "Arithmetic Expansion" in...
You are
- using "Arithmetic Expansion" in lieu of "Command Substitution"
- NOT expandig the variables num1 and num2
3,052
Posted By MadeInGermany
And if you *want* bc, maybe for handling very...
And if you *want* bc, maybe for handling very long numbers, then it is
num1=12345678901234567890
num2=46
mod_final=$( echo "$num1%$num2" | bc )
=>Command substitution.
9,139
Posted By bakunin
Yes, and as you have already received the...
Yes, and as you have already received the solution i wil concentrate on explaining the reason:

When you invoke a process with some arguments these arguments become part of the "process...
14,695
Posted By RudiC
There are no array operations for the...
There are no array operations for the not-that-common things you want to do. You'll need to take the scenic route, as did jgt, if you don't play tricks.

If you just need an array to hold the...
3,567
Posted By RudiC
grep builds one overall pattern to match in the...
grep builds one overall pattern to match in the file(s) and thus can only yield one count. Use either four greps, one for every single keyword, or try
awk -vKEYS="Exception Fatal Error Exec" '...
3,567
Posted By drl
Hi. Using a pipeline grep -> sort -> uniq: ...
Hi.

Using a pipeline grep -> sort -> uniq:
#!/usr/bin/env bash

# @(#) s1 Demonstrate count of 4 unique strings, grep, sort, uniq.

# Utility functions: print-as-echo,...
10,012
Posted By jim mcnamara
bash already supports associative arrays, so IMO...
bash already supports associative arrays, so IMO the need for linked lists may not be all that critical. Chubler XL gave a really good take on it.
Associative arrays require bash v4

declare -A...
10,012
Posted By Chubler_XL
I'd use arrays. One for the values and one for...
I'd use arrays. One for the values and one for the next index.


Here is an example of a sorted linked list:

llinsert() {
local END=${#LST[@]}
local i

for((i=0; NXT[i];...
2,275
Posted By drl
Hi. As with other non-oracle solutions such...
Hi.

As with other non-oracle solutions such as awk, perl, here is datamash:
#!/usr/bin/env bash

# @(#) s1 Demonstrate statistics for grouped data, datamash.

# Utility functions:...
2,275
Posted By Aia
perl -nalF',' -e ' print "@F[0],MIN,MAX" and...
perl -nalF',' -e '
print "@F[0],MIN,MAX" and next if $. == 1;
push @{$o{$F[0]}}, $F[1];
END{ for( sort keys %o ){ @so = sort @{ $o{$_} };
$l = $so[-1] ? $so[-1] : $so[0];
print...
2,275
Posted By vgersh99
awk -F, -f muk.awk myFile OFS=, where muk.awk is:...
awk -F, -f muk.awk myFile OFS=, where muk.awk is:

FNR>1 {
if (!($1 in amin))
amin[$1]=amax[$1]=$2
else {
if($2<amin[$1]) amin[$1]=$2
if($2>amax[$1]) amax[$1]=$2
}...
2,275
Posted By Scrutinizer
Hi, try: awk ' NR==1 { next } ...
Hi, try:
awk '
NR==1 {
next
}

!($1 in L) {
L[$1]=$2
}

$2<L[$1] {
L[$1]=$2
}

$2>=H[$1] {
H[$1]=$2
}

END {
for(i in L) print i, L[i], H[i]
2,275
Posted By bakunin
I have actually written a whole article about...
I have actually written a whole article about exactly this:

https://www.unix.com/tips-and-tutorials/209439-how-do-control-break-algorithm.html

I hope this helps.

bakunin
Forum: Tips and Tutorials 12-08-2012
9,887
Posted By bakunin
How to do a "Control Break" (Algorithm)
A vast amount of problems asked in "Shell Programming an Scripting" can be traced back to be an application of a basic algorithm called a Control Break. Every programmer - and script writers are...
27,669
Posted By Aia
Try find /home/arpu/test -type f -name...
Try

find /home/arpu/test -type f -name '*.txt' | while read f; do mv -v "$f" "${f%.*}.bak"; done

-type f is there so there is not chance of renaming a directory named something.txt, if exists
2,686
Posted By elixir_sinari
This will look for lines, in the file named by...
This will look for lines, in the file named by $fname, not matching (-v) the strings (that's the use of fgrep) contained in the file (-f) infile, and redirect those lines to tmp.tmp.
2,686
Posted By Yoda
Try this:- #!/bin/bash while read line ...
Try this:-

#!/bin/bash
while read line
do
for i in $(find /tmp/myproject/content_to_remove/config/ -type f)
do
DIR=`echo $i | sed 's|\(.*\)/.*|\1|'`
sed...
1,363
Posted By elixir_sinari
Read the man page for split.
Read the man page for split.
1,221
Posted By pamu
for i in $(find statement) do new_name=$(echo...
for i in $(find statement)
do
new_name=$(echo $i | sed 's/-e/-l/g')
echo "mv $i $new_name"
done
if you are getting your required result. Just remove echo.:)
Showing results 1 to 25 of 33

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