Remove character in Shell Script

Asked

Viewed 1,137 times

1

all right?

I’m making a script to read a log on my server to pick up just a few parts that interest me and play in a . csv.

The script is very simple, follow:

  #!/bin/bash


export TMPARQ=/datasets/SCRIPTS/TMP/logjob.txt
export FILTER=/datasets/SCRIPTS/TMP/logjob2.txt
PROJ=$1
JOB=$2

cd /opt/IBM/InformationServer/Server/DSEngine/
. ./dsenv
dsjob -logsum $PROJ $JOB > $TMPARQ

grep -A 1 "rows inserted on the current node" $TMPARQ > $FILTER

cat $FILTER | grep INFO | cut -d':' -f1-3 | cut -c16-42 > /datasets/SCRIPTS/TMP/data.txt

grep "inserted on the current node:" $TMPARQ | cut -d":" -f3 > /datasets/SCRIPTS/TMP/volumetria.txt

cd /datasets/SCRIPTS/TMP/
paste data.txt volumetria.txt > GeraInfoVolumetria.txt

cat GeraInfoVolumetria.txt
cat GeraInfoVolumetria.txt >> HistoricoVolumetria.csv

I have a question when generating the volumetric file.txt A complete line of the original log is as follows:

Orcllog,1: Number of Rows inserted on the Current Node: 66.

I need to get the number after the ":" in case 66 What happens is that the.txt volumetric file is second saved also with the dot after the number. I tried to use a grep -v "." but removes the entire line.

Here is the txt example:

Jan 10 19:37:28 2019     0.
Jan 10 20:08:33 2019     66.
Jan 10 20:08:33 2019     66.

Numbers can vary in different characters, up to more than 9999 Can someone help me get that blessed point? haha

Thank you

  • I am new to shell script. If you can leave comments and suggestions about the code, I would be extremely grateful/

  • Using a PCRE it is possible to capture the desired number in the expression with a single grep.

1 answer

2

There are several ways to do this and one of them, using the cut, would be:

echo "OrclLog,1: Number of rows inserted on the current node: 66." |\
    cut -d":" -f3 | cut -d"." -f1

And the result would be " 66" (there’s still space in the front).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.