I have an input file txt, like this
999844634|715717657|1508241298 |000018995|INSTALACION DECO + PUNTO TV ADIC DIGITAL|000000001|ALTA |73479107 |2019-03-15|246221122|0001|671564720|002|DNI|02842909 |
999844634|715717657|1508241298 |000021932|DECODER HD ZAPPER COMODATO |000000001|ALTA |73479107 |2019-03-15|246221122|0001|671564720|002|DNI|02842909 |
999844634|715717657|1508241298 |000021932|DECODER HD ZAPPER COMODATO |000000001|ALTA |73479107 |2019-03-15|246221122|0001|671564720|002|DNI|02842909 |
999846100|745304617|1501278792 |000018995|INSTALACION DECO + PUNTO TV ADIC DIGITAL|000000001|ALTA |12544155 |2019-03-15|248309282|0002|774235318|003|DNI|29600747 |
999846100|745304617|1501278792 |000021148|BLOQUE CATV FULL HD |000000001|ALTA |12544155 |2019-03-15|248309282|0002|774235318|003|DNI|29600747 |
999846100|745304617|1501278792 |000021251|DECODIFICADOR SD TV VENTA CATV |000000046|BAJA MIGRACION DE P/S |12544155 |2019-03-15|248309282|0001|774235318|003|DNI|29600747 |
999846100|745304617|1501278792 |000021956|INSTALACION PUNTO TV ANALOGICO ALTA |000000046|BAJA MIGRACION DE P/S |12544155 |2019-03-15|248309282|0001|774235318|003|DNI|29600747 |
and I have a script that converts this data
system=ATIS
username=AUTOMATICO
fecha=$(date +"%Y%m%d_%H%M%S")
header="$system|$file|$fecha|$username|"
#echo $header
## quitar espacios tr -s " "
## concatenar sed -e 's/^/'$header'/g'
## cadena awk -F'|' '{print $6"|"$7"|"$14"|"$15"|"$8"|"$4}'
#### ALTA
operacion="ALTA|"
temp1=$(cat $file | grep -i -e '001.*ALTA' | awk -F'|' '{print $14"|"$15"|"$8"|"$4}' | sed -e 's/^/'$header$operacion'/g' | sed -e 's/ //g' )
#### ELIMINAR
operacion="ELIMINAR|"
temp2=$(cat $file | grep -i -e '046.*BAJA FINAL' -e '008.*BAJA FINAL' -e '012.*BAJA FINAL' | awk -F'|' '{print $14"|"$15"|"$8"|"$4}' | sed -e 's/^/'$header$operacion'/g' | sed -e 's/ //g' )
#### BAJA
operacion="BAJA|"
temp3=$(cat $file | grep -i -e '008.*BAJA APC' -e '046.*BAJA MIGRACION' | awk -F'|' '{print $14"|"$15"|"$8"|"$4}' | sed -e 's/^/'$header$operacion'/g' | sed -e 's/ //g' )
#### ACTIVAR
operacion="ACTIVAR|"
temp4=$(cat $file | grep -i -e '027.*RECONEXION APC' -e '028.*RECONEXION DEUDA' -e '042.*RECONEXION TIPIFICADA' | awk -F'|' '{print $14"|"$15"|"$8"|"$4}' | sed -e 's/^/'$header$operacion'/g' | sed -e 's/ //g' )
#### DESACTIVAR
operacion="DESACTIVAR|"
temp5=$(cat $file | grep -i -e '031.*SUSPENSION APC' -e '032.*SUSPENSION PARCIAL DEUDA' -e '033.*SUSPENSION TOTAL DEUDA' -e '040.*SUSPENCION TIPIFICADA PARCIAL' -e '041.*SUSPENCION TIPIFICADA TOTAL' | awk -F'|' '{print $14"|"$15"|"$8"|"$4}' | sed -e 's/^/'$header$operacion'/g' | sed -e 's/ //g' )
#### MANTENER
temp6=$(cat $file | grep -i -e '046.*ALTA - BAJA MIGRACION' -e '047.*ALTA - BAJA MIGRACION' | awk -F'|' '{print $14"|"$15"|"$8"|"$4}' | sed -e 's/^/'$header$operacion'/g' | sed -e 's/ //g' )
#### CAMBIO TITULARIDAD
operacion="CAMBTITU|"
temp7=$(cat $file | grep -i -e '018.*CAMBIO DE TITULAR' | awk -F'|' '{print $14"|"$15"|"$8"|"$4}' | sed -e 's/^/'$header$operacion'/g' | sed -e 's/ //g' )
##armar los archivos
#echo "$temp1" > ATIS_ALTA_temp.txt
#echo "$temp2" > ATIS_ELIMINAR_temp.txt
#echo "$temp3" > ATIS_BAJA_temp.txt
#echo "$temp4" > ATIS_ACTIVAR_temp.txt
#echo "$temp5" > ATIS_DESACTIVAR.txt
echo "$temp1" > ${system}_ALL.txt
echo "$temp2" >> ${system}_ALL.txt
echo "$temp3" >> ${system}_ALL.txt
echo "$temp4" >> ${system}_ALL.txt
echo "$temp5" >> ${system}_ALL.txt
echo "$temp7" >> ${system}_ALL.txt
in this data output
ATIS|testArnold2.txt|20190408_111317|AUTOMATICO|ALTA|DNI|02842909|73479107|000018995
ATIS|testArnold2.txt|20190408_111317|AUTOMATICO|ALTA|DNI|02842909|73479107|000021932
ATIS|testArnold2.txt|20190408_111317|AUTOMATICO|ALTA|DNI|02842909|73479107|000021932
ATIS|testArnold2.txt|20190408_111317|AUTOMATICO|ALTA|DNI|29600747|12544155|000018995
ATIS|testArnold2.txt|20190408_111317|AUTOMATICO|ALTA|DNI|29600747|12544155|000021148
ATIS|testArnold2.txt|20190408_111317|AUTOMATICO|BAJA|DNI|29600747|12544155|000021251
ATIS|testArnold2.txt|20190408_111317|AUTOMATICO|BAJA|DNI|29600747|12544155|000021956
but I want my output to be in the same order as income because sometimes it is so much data and filters mess up, how do I write it in the same order in which it enters?
IIUC, you want to map a bunch of patterns into different operations. If so, you can use awk with the following code sample:
$ cat t18.awk
# here we set up "|" and optional surrounding spaces as FS, so no need
# to run sed to remove extra spaces
# OFS="|", header will be feed from the command line with -v option
BEGIN{ FS = " *\\| *"; OFS = "|"; }
# use if/else to find operation based on pattern in your "grep" commands
# I just added three, you need to add rest of them to the function
function find_operation() {
if (/001.*ALTA/) return "ALTA"
else if (/(046|008).*BAJA FINAL/) return "ELIMINAR"
else if (/008.*BAJA APC|046.*BAJA MIGRACION/) return "BAJA"
else return ""
}
# run the function(), if operation is not EMPTY, print it
operation = find_operation() {
print header, operation, $14, $15, $8, $4
}
I run the above on my MacOS, and it yields the following:
$ header="ATIS|testArnold2.txt|data|atok"
$ awk -v header="$header" -f t18.awk file.txt
ATIS|testArnold2.txt|data|atok|ALTA|DNI|02842909|73479107|000018995
ATIS|testArnold2.txt|data|atok|ALTA|DNI|02842909|73479107|000021932
ATIS|testArnold2.txt|data|atok|ALTA|DNI|02842909|73479107|000021932
ATIS|testArnold2.txt|data|atok|ALTA|DNI|29600747|12544155|000018995
ATIS|testArnold2.txt|data|atok|ALTA|DNI|29600747|12544155|000021148
ATIS|testArnold2.txt|data|atok|BAJA|DNI|29600747|12544155|000021251
ATIS|testArnold2.txt|data|atok|BAJA|DNI|29600747|12544155|000021956
Certainly, you should change the header to what you defined in your code, just remove the trailing pipe |.
Related
I want to make a file, for.sh, in the gnuplot script during its execution. The new file then will be called in the gnuplot script as
set xtics (`(sh for.sh)`)
The contents in for.sh should be these.
#!/bin/bash
rm Final-X-ticks.dat
KPATH=data1
TICK_position=data2
sed -n '/crystal coordinates with respect/,/REPRODUCED(TRANSFORMED) DATASET/p' $KPATH | sed '/crystal/d' | sed '/REPRODUCED/d' | awk '{print $4}' | sed -r '/^\s*$/d' > symbl.dat
line=$(cat symbl.dat | wc -l)
for i in `seq 1 1 $line`
do
echo " '{/Times-New " > symbl-$i.dat
cat symbl.dat | tail -n $line | head -n "$i" | tail -n 1 >> symbl-$i.dat
echo " }'" >> symbl-$i.dat
grep -i "coordinate" $TICK_position | awk '{print $NF}' | head -n "$i" | tail -n 1 >> kpoints-$i.dat
cat kpoints-$i.dat | tail -n 1 | awk 'BEGIN { ORS = " " } { print }' >> symbl-$i.dat
echo " ," >> symbl-$i.dat
cat symbl-$i.dat | awk 'BEGIN { ORS = " " } { print }' | awk '{gsub(/Times-New[ \t]+(G|\$\\Gamma\$)/, "Symbol G")} 1' | awk 'BEGIN { ORS = " " } { print }' >> Final-X-ticks.dat
done
rm symbl-* symbl.dat kpoints-*
I tried with
cat > for.sh <<EOF
above contents
EOF
but it gives me error
cat for.sh << EOF
^
"plot.gnu", line 19: invalid command
You can use a datablock to hold the text, then print it out. For example,
$MYSCRIPT <<EOF
#!/bin/bash
rm Final-X-ticks.dat
...
rm symbl-* symbl.dat kpoints-*
EOF
set print "for.sh"
print $MYSCRIPT
set print
set xtics (`(bash ./for.sh)`)
I have a simple shell script for installing Jenkins plugins:
installPlugin() {
{...}
}
for f in ${plugin_dir}/*.hpi ; do
#without optionals
deps=$( unzip -p ${f} META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | grep -v "resolution:=optional" | tr '\n' ' ' )
for plugin in $deps; do
installPlugin "$plugin" 1 && changed=1
done
done
I'm calling this script from a Dockerfile like so:
RUN JENKINS_HOME=$JENKINS_HOME \
http_proxy=$http_proxy \
https_proxy=$https_proxy \
$JENKINS_HOME/install_plugin.sh \
ace-editor:1.1 \
Even though the unzip routine is not installed in the Dockerfile, when I run docker build the output is still SUCCESSFUL even though unzip is missing. I would like to fail the build if the following step fails:
deps=$( unzip -p ${f} META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | grep -v "resolution:=optional" | tr '\n' ' ' )
Any help is much appreciated!
LE
The script outputs the following:
/var/jenkins/install_plugin.sh: line 62: unzip: command not found
deps=
However, the docker build doesn't fail even if that script failed:
Successfully built 54f5a5ec567d
I ended up doing an empty check like this:
for f in ${plugin_dir}/*.hpi ; do
manifestMf=$(unzip -p ${f} META-INF/MANIFEST.MF | tr -d '\r')
if [ $manifestMf=="" ]; then
echo "Invalid META-INF/MANIFEST inside $f"
exit 1
fi;
#without optionals
deps=$(echo $manifestMf | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | grep -v "resolution:=optional" | tr '\n' ' ' )
# with optionals
#deps=$( unzip -p ${f} META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | tr '\n' ' ' )
for plugin in $deps; do
installPlugin "$plugin" 1 && changed=1
done
done
done
I have a task which asks to write a script which displays all partitions formatted with a specific file system, given as parameter.
I have written the script but when i run it it displays '0'. What am i doing wrong?
This is my code:
#!/bin/bash
n=sudo parted -l | tail -n +8 | awk '{print $5}' | wc | awk '{print $2}'
m=sudo parted -l | tail -n +8 | awk '{print $5}'
q=sudo parted -l | tail -n +8
for i in $n; do
if [ "[ $m | sed -n ip ]" = "$1" ]; then
echo "$q | sed -n ip"
fi
done
Different approach from yours, but does it do what you need?
lsblk -f | awk '$0 ~ fs {print $NF}' fs=ext2
Can I use hexdump in a shell script?
When I use it I keep getting an error .
syntax error near unexpected token 'hexdump'
#!/bin/bash
#bash-hexdump
# Quick script to check delay of the shotpoints
echo " please enter the complete line name as mentioned in the RAID2 "
read $line
cd /argus/raid2/"$line"
echo
echo " Entering the directory "
echo
for file in /argus/raid2/"$line"/*.ffid
hexdump -e "16 \"%_p\" \"\\n\"" $FFID | sed -n '68,73p' > list1
done
for filename in 'cat list1'
do
sed -n 6p | awk '{print $1}' = $wd
cat list.txt | sed -n 1p | cut -c13-14 = $hh
cat list.txt | sed -n 1p | cut -c15-16 = $mm
cat list.txt | sed -n 2p | cut -c1-2 = $ss
done
while [ true ]
do
$FFID=`ls -1rt $1 | grep -i ffid | tail -1`
echo " FFID value is : $FFID"
while [ $FFID = `ls -1rt $1 | grep -i ffid | tail -1` ]
do
hexdump -e "16 \"%_p\" \"\\n\"" $FFID | sed -n '68,73p' > list
done
for filename in 'cat list'
do
cat list.txt | sed -n 1p | cut -c13-14 = $hh1
cat list.txt | sed -n 1p | cut -c15-16 = $mm1
cat list.txt | sed -n 2p | cut -c1-2 = $ss1
done
$time1 = "$hh"":""$mm"":""$ss" ;
$time2 = "$hh1"":""$mm1"":""$ss1" ;
$former_seconds = $(date --date= "$time1" +%s);
$later_seconds = $(date --date= "$time2" +%s);
$time_delay = ( "$later_seconds" - "$former_seconds" )
$wb_time = ( "$wd" * 1.33 )
if
(("$wb_time" + "$time_delay")) < 12.0
then
echo "please slow down"
fi
if [ -e EOL.ffid ]
then
echo "EOL.ffid detected, exiting script"
exit
fi
done
I am not able to figure out why the hexdump code is giving me an error . Please help .
You are missing the do in your for loop:
for file in /argus/raid2/"$line"/*.ffid
do
hexdump -e "16 \"%_p\" \"\\n\"" $FFID | sed -n '68,73p' > list1
done
I currently have a script that checks the MAC address, tt looks like this
"m"|"-m" )
if [ ! -n "$2" ]
then
echo "Enter MAC address"
exit 0
fi
out1=`cat $dhcp_files/* | grep -i "$2" 2>/dev/null`
ip=`cat $dhcp_files/* | grep -i "$2" | awk '{print $8}' | sed s/\;//g 2>/dev/null`
out=` grep -i $ip $shapy/* | awk '{print $8}' 2>/dev/null`
echo -en ''$out1' on '$out' \n'
this is done like that: ./mac_check -m 00:00:00:00:00:00
The result of this script:
host Jon_Rosewelt_6_5 { hardware ethernet 00:1d:4e:b5:d4:10; fixed-address 192.168.101.19; } on eth4
but I would like to do to the script received any form of mac address
aka. ./check_mac -m 001d.4eb5.d410 **or** 001d4eb5d410 **or** 00-1d-4e-b5-d4-10
How can I do that?
With GNU sed and Solaris sed:
echo 001d.4eb5.d410 | sed 's/[^0-9a-f]//g;s/../&:/g;s/:$//'
echo 001d4eb5d410 | sed 's/[^0-9a-f]//g;s/../&:/g;s/:$//'
echo 00-1d-4e-b5-d4-10 | sed 's/[^0-9a-f]//g;s/../&:/g;s/:$//'
echo 00:1d:4e:b5:d4:10 | sed 's/[^0-9a-f]//g;s/../&:/g;s/:$//'
Output:
00:1d:4e:b5:d4:10
00:1d:4e:b5:d4:10
00:1d:4e:b5:d4:10
00:1d:4e:b5:d4:10
With your code:
"m"|"-m" )
mac="$2" # added
if [ ! -n "$mac" ] # changed
then
echo "Enter MAC address"
exit 0
fi
mac="$(echo "$mac" | sed 's/[^0-9a-f]//g;s/../&:/g;s/:$//')" # added
out1=`cat $dhcp_files/* | grep -i "$mac" 2>/dev/null` # changed
ip=`cat $dhcp_files/* | grep -i "$mac" | awk '{print $8}' | sed s/\;//g 2>/dev/null` # changed
out=` grep -i $ip $shapy/* | awk '{print $8}' 2>/dev/null`
echo -en ''$out1' on '$out' \n'