Entradas

Replace patterns in a file

#!/bin/bash # February 3th, 2018 # Create a table copy in the same database # shPid=$$ inputSqlFile=statement.sql tmp=".sql.${shPid}" newInputSqlFile=statement_$shPid.sql pattern="alter table" target_tableName="tmp.people_copy" source_tableName="tb01.people" input_tablespace="ss" tablespaceName="in $input_tablespace" if [ -z "$input_tablespace" ] ; then     tablespaceName="" fi rTarget_table="target_table" rSourve_table="source_table" rTablespace="in_tablespace" echo "$inputSqlFile" sed "/$pattern/Q" $inputSqlFile > $tmp cp $inputSqlFile $tmp sed "s/${rTarget_table}/${target_tableName}/" $tmp > $newInputSqlFile sed "s/${rSourve_table}/${source_tableName}/" $newInputSqlFile > $tmp sed "s/${rTablespace}/${tablespaceName}/" $tmp > $newInputSqlFile cat $newInputSqlFile rm $tmp rm $newInputSqlFile ----------------------...

Sed: Extract a file's part with sed command

#!/bin/bash # February 3rd, 2018 export Me=$(basename $0 .sh) export fecha_actual=`date "+%Y-%m-%d_%H%M%S"` inputFile=notas.txt pattern="find" # cut the file here echo "$inputFile" # q: show the file until the pattern, including it. # Q: show the file until the pattern, NOT including it. sed "/$pattern/Q" $inputFile

WordCount

Count word using Hadoop package com.ciocomit.count; import java.io.IOException; import java.util.StringTokenizer; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; public class WordCount {     public static class Map extends Mapper {         public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {             String line = value.to...

AWK: n lines before, m lines after

awk 'c-->0; $0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=3 a=5 s="cadenita" short.txt

Git Merge

git granch                        # local branches git branch -r                   # remote branches git branch -a                   # local and remote branches git status                         # current branch status git checkout develop      # go to "develop" branch git checkout hotfix/tk_01_inv     # go to "hotfix/tk_01_inv" branch git pull    # download the remote changes into current branch git add .    # save all changes git commit -m 'some comment'    # commit into local branch git push      # public my local changes into remote git repository git merge : "develop" branch...

Unix shell scripting: Full Log

Creating of a Shell Scripting full log. #!/bin/bash -x export Me=`basename $0 .sh` { export current_date=`date "+%Y-%m-%d_%H%M%S"` # echo "Me: $Me" echo "Current Date: $current_date" echo -e "Successful Job. \n\n\n" exit 0 } > ${Me}".log1" 2> ${Me}".log2" Results full_log.log1 Me: full_log Current Date: 2017-05-14_200038 Successful Job. full_log.log2 ++ date +%Y-%m-%d_%H%M%S + export current_date=2017-05-14_200038 + current_date=2017-05-14_200038 + echo 'Me: full_log' + echo 'Current Date: 2017-05-14_200038' + echo -e 'Successful Job. \n\n\n' + exit 0
PERL: Dígito verificador con Perl (Chile). #!/usr/bin/perl use strict; use warnings; my $s_Rut = "30686957"; my @a_rut = split '', $s_Rut; print("@a_rut" ."\n"); my @rut_rev = reverse @a_rut; print("@rut_rev" ."\n"); my $adding=0; my $multi=2; foreach my $n (@rut_rev) {   print ("$n \n");   $adding = $adding + ($n * $multi++);   if($multi==8){       $multi=2;   } } print ("$adding \n"); my $module=$adding%11; my $dv=11-$module; if($dv == 11){     $dv=0; } if($dv == 10){     $dv='K'; } $s_Rut="$s_Rut-$dv"; print("RUT: $s_Rut\n");