Mostrando postagens com marcador Shellscript. Mostrar todas as postagens
Mostrando postagens com marcador Shellscript. Mostrar todas as postagens

domingo, 4 de março de 2012

Shell: Cat Command Examples

To create a file called "foo.txt", enter:
cat >foo.txt
Unix is the best.
<control-D>

You can combine two files and creates a new file called report.txt, enter:
cat score.txt names.txt > report.txt

To append (add data to existing) data to a file called foo.txt, enter:
cat >>foo.txt
A champion is someone who gets up, even when he can't
<control-D>

You can send files to sound devices such as /dev/dsp or /dev/audio to make sure sound output and input is working:

cat filename >/dev/dsp
cat recording.au >/dev/audio

You can simply use the following command for recording voice sample and play back with it cat command:

dd bs=8k count=4 </dev/audio >testing123.au
cat testing123.au >/dev/audio

No cat cannot print in reverse order but tac command can concatenate and print files in reverse:

tac fileName
cat fileName | tac
tac <<<"$myFileName"

Referência: Linux / Unix: Cat Command Examples

quarta-feira, 13 de julho de 2011

Shell: Using while loop to read file lines

while IFS= read -r LINE ; do echo "$(date) $LINE" ; done < 20110603-105216.log

Shell: Skip First Two Fields and Print the Rest of Line

Using awk:
$ echo 'This is a test blah foo bar etc' | awk '{print substr($0, index($0,$3))}'
a test blah foo bar etc

Using cut:
$ echo 'This is a test blah foo bar etc' | cut -d ' ' -f3-
a test blah foo bar etc

sábado, 9 de julho de 2011

Shell: Read An Array Using C Style For Loop

$ CONCEITO=("ruim" "fraco" "mediano" "bom" "muito bom" "excelente") ; \

for((i=1;i<11;i++)) ; do echo "#$i = ${CONCEITO[$(($RANDOM%6))]}" ; done



#1 = excelente

#2 = fraco

#3 = ruim

#4 = bom

#5 = ruim

#6 = excelente

#7 = mediano

#8 = mediano

#9 = excelente

#10 = muito bom





Obs: Array length: ${#CONCEITO[@]}

domingo, 26 de junho de 2011

Shell: Count Number of Characters in a String

x="This is a test"
y="${x//[^s]}"
echo "$y"
echo "${#y}"


To match both 's' and 'S', enter:

x="This is a test. S"
y="${x//[^s|S]}"
echo "${#y}"

quinta-feira, 26 de maio de 2011

Shell: Find and remove dead links

$ find -L -type l -exec rm -f {} \;

Shell: What are lines which are repeated ?

$ cat file.txt
21421415
42657547
65765234
85685634
24246547
12336467
76545253
12336467
46565865
65464364
34668747
21421415
67475473
$ cat file.txt | sort | uniq -c | \
awk '{ if ($1 > 1) { print $2 } }'
12336467
21421415

quinta-feira, 19 de maio de 2011

Shell: Output the common lines of two text files

One way:
$ diff --side-by-side file_a file_b | grep -n -v "[|<>]"

Or using the command 'comm' (man comm for more details):
$ comm -12 file_a file_b

terça-feira, 26 de abril de 2011

Shell: Remove Last Character From String / Line / Word

The % is bash parameter substitution operators which remove from shortest rear (end) pattern.

$ x="foo bar"
$ echo "${x%?}"
$ foo ba

Referência: nixCraft

segunda-feira, 15 de novembro de 2010

Shell: Battery monitor

BATTERY_DEVICE=$(hal-find-by-property --key info.category --string battery | head -n 1)
if test -z "${BATTERY_DEVICE}" ; then
BATTERY=0
else
BATTERY=$(hal-get-property --udi ${BATTERY_DEVICE} --key battery.charge_level.percentage)
fi
echo " ${BATTERY}% "

sexta-feira, 15 de outubro de 2010

Shell: Check if variable is a number


echo $X | egrep '^[0-9]+$' >/dev/null 2>&1
if [ "$?" -eq "0" ]; then
echo "Postive integer here...."
else
echo "Something else...."
fi

Drunk Penguins

Drunk Penguins
Drunk Penguins