Search Results

Search: Posts Made By: frans
2,686
Posted By frans
If they must be exactly the same ...
If they must be exactly the same
systime=2011-05-13:18:45
shubtime=2011-05-13:18:30
if [ "$systime" = "$shubtime" ]
then
echo" OK"
else
echo "NOK"
fi
Or shorter:[ "$systime" =...
6,635
Posted By frans
#!/bin/bash ##!/bin/bash var2="bgroup = set...
#!/bin/bash
##!/bin/bash
var2="bgroup = set bgroup port"
var3="utm = set security utm"
echo "$var2 --> '${var2# = }'"
echo "$var3 --> '${var3# = }'"
# You can also
for V in var2 var3; do
...
51,828
Posted By frans
Could be written (with arithmetic evaluation and...
Could be written (with arithmetic evaluation and array)
#!/usr/bin/bash
parity=(even odd) # parity[0]='even' parity[1]='odd'
read -p "enter a number: " a
echo "the number is ${parity[$((a%2))]}
7,697
Posted By frans
No need to mkdir -p /foo if you already mkdir -p...
No need to mkdir -p /foo if you already mkdir -p /foo/dir1 as the -p option creates parents.

#!/bin/bash
for d1 in boo doo foo; do
for d2 in dir1 dir2; do
mkdir -p /$d1/$d2
...
5,240
Posted By frans
#!/bin/bash while IFS='&' read -a L do ...
#!/bin/bash
while IFS='&' read -a L
do
for i in ${!L[@]}; do
eval "${L[$i]}"
done
for V in poc ooc mjv omj mov ps rel bod oxi ozn lang loc
do
echo -en "$V=${!V}\t"
...
5,461
Posted By frans
If you have GNU date $ D1="5/21/2010 9:14:00...
If you have GNU date
$ D1="5/21/2010 9:14:00 AM"
$ D2="5/24/2010 7:23:00 AM"
$ DM=$((($(date -d "$D2" +%s)-$(date -d "$D1" +%s))/60))
$ printf "%s:%02d\n" $((DM/60)) $((DM%60))
70:09
2,136
Posted By frans
Just an example of how it can be done (first get...
Just an example of how it can be done (first get rid of the GOTO):
#!/bin/bash
while : ; do
echo "SELECT OPTION"
echo "-------------"
echo "1- Create username"
echo "2- Create...
1,428
Posted By frans
Please, use code tags. Somthing like if...
Please, use code tags.
Somthing like
if (($#<2)); then
echo "There must be at least 2 parameters (pattern, file)"
exit 1
fi
Pattern="$1"
shift
Response=$(grep "$Pattern" "$@")
#...
59,088
Posted By frans
Why store it? (but it's preferable to store the...
Why store it? (but it's preferable to store the date string to avoid calls to date in the iteration.
#!/bin/bash
D=$(date +%d-%m-%Y)
for F in *.*
do
mv $F ${F%.*}-$D.${F##*.}"
done
1,953
Posted By frans
Please, use code tags to make the code more...
Please, use code tags to make the code more readable.
Howto:

Select the text corresponding to code
Click on the 'code' button in the editor's...
2,676
Posted By frans
What's the output of this: #!/bin/bash while...
What's the output of this:
#!/bin/bash
while IFS=':=' read A B C
do
echo "A='$A' B='$B' C='$C'"
done <$INFILE

---------- Post updated at 23:06 ---------- Previous update was at 21:52...
1,629
Posted By frans
egrep: F=570345 echo *${F}* | grep -E...
egrep:
F=570345
echo *${F}* | grep -E '[^0-9]$F[^0-9]'
# ls *${F}* | grep -E '[^0-9]$F[^0-9]' # If the previous doesn't work
1,067
Posted By frans
Yes I can !
Yes I can !
1,063
Posted By frans
#!/bin/bash while IFS='<>' read Null Tag Val...
#!/bin/bash
while IFS='<>' read Null Tag Val Null
do
case $Tag in
free-energy)
echo $Val
Pos=0 ;;
position)
((Pos++))
((Pos%2)) && echo -n...
5,201
Posted By frans
Simple while read file do rm -f FolderB/$file...
Simple
while read file
do rm -f FolderB/$file
done < <(ls FolderA)
4,583
Posted By frans
No need to count the lines: while read L do ...
No need to count the lines:
while read L
do
echo "$L"
done <playerlist
Above code reads each line of playerlist and assigns it to the variable L; then prints the variable on screen, until...
3,495
Posted By frans
grep -i 'model name' /proc/cpuinfo | cut -d: -f2...
grep -i 'model name' /proc/cpuinfo | cut -d: -f2 | head -1
1,376
Posted By frans
With the GNU date: LIMIT=$(date -d '-8 days'...
With the GNU date:
LIMIT=$(date -d '-8 days' '+%Y/%m/%d')
while IFS='|'; read D L
do [[ $D > $LIMIT ]] && echo "$D|$L"
done < infile
awk:
awk -F'|' -vD=$(date -d '-8 days' '+%Y/%m/%d') '$1 > D'...
14,887
Posted By frans
getting parameters in a function is the same as...
getting parameters in a function is the same as in a script. If you call the script like InsertRecord "$OLD_VAL" "$NEW_VAL" "$DATE"
you can retrieve the values inside the function (as in your...
3,877
Posted By frans
sed
sed -e 's/ [^ ]*\.log//g' -e 's/ / /g' -e 's/^ //' file
To modify file in place
sed -i -e 's/ [^ ]*\.log//g' -e 's/ / /g' -e 's/^ //' file
If -i option isn't available, you can redirect outpu to...
2,197
Posted By frans
bash + GNU date
#!/bin/bash
S2D () { date -u --date "19700101 $1 sec" "+%Y-%m-%d %T";} # Converts timestamp to readable date
while read A B C
do
T=$(date -d "${B::8} ${B:8:2}:${B:10:2}:${B:12:2}" +%s)
...
2,862
Posted By frans
The script works fine when recorded in a file but...
The script works fine when recorded in a file but gives me the same strange output when pasted into a terminal.
-----------

Now works if line 1. (function) is
#
NewName() { A=${1%%.*};...
10,109
Posted By frans
#!/bin/bash while ((i<1000)) do ...
#!/bin/bash
while ((i<1000))
do
N=$((RANDOM*1000000/32768))$((RANDOM*1000000/32768))
echo "${A }" | grep $N && continue # if number already in the array
A[$i]=$N
((i++))
tput...
4,965
Posted By frans
I think you're right. for F in...
I think you're right.
for F in /back_YY.MM.DD/backup1 /back_YY.MM.DD/backup2
do echo ${F%/*}/${F#/*/}_${F:6:2}${F:9:2}${F:12:2}.tar.gz
done
result
/back_YY.MM.DD/backup1_YYMMDD.tar.gz...
1,615
Posted By frans
this should work #!/bin/bash head -1 file ...
this should work

#!/bin/bash
head -1 file
while read L
do
N=${L%.*}; N=${N##*\"}
((N>=23)) && ((N<60)) && echo $L
done < file
Showing results 1 to 25 of 53

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