AllSetup
  • Introduction
  • Docker
  • Common commands
    • Various S3 utilities
    • Mac stuff
  • Mac stuff
  • Dockerfile examples
  • Docker GPU
  • TensorFlow
  • tensorFlow on iOS
  • Jupyter
  • iOS
  • SSD work
  • SSD using Inception
  • Object Detection
  • Docker GPU
  • TitBits
  • MySQL
  • FAIR Multipathnet
  • Git and GitFlow
  • Java Scala Mongo Installation
  • Devops
  • scratchpad
  • GCP Production
  • GStreamer
  • bash
  • Scala
  • Unix commands
  • Publish-Subscribe
  • Sensor-project
  • Flutter-project
Powered by GitBook
On this page
  • To replace a string pattern with empty string in a file
  • AWK

Was this helpful?

bash

PreviousGStreamerNextScala

Last updated 5 years ago

Was this helpful?

If conditions

Ref:

#!/bin/bash

a=4
b=5

#  Here "a" and "b" can be treated either as integers or strings.
#  There is some blurring between the arithmetic and string comparisons,
#+ since Bash variables are not strongly typed.

#  Bash permits integer operations and comparisons on variables
#+ whose value consists of all-integer characters.
#  Caution advised, however.

echo

if [ "$a" -ne "$b" ]
then
  echo "$a is not equal to $b"
  echo "(arithmetic comparison)"
fi

echo

if [ "$a" != "$b" ]
then
  echo "$a is not equal to $b."
  echo "(string comparison)"
  #     "4"  != "5"
  # ASCII 52 != ASCII 53
fi

# In this particular instance, both "-ne" and "!=" work.

echo

exit 0

To replace a string pattern with empty string in a file

files contains the following strings
  pic_000_1549487577_generic_combo_0_crop_001.jpg   green    [good: 0.01,  green: 0.99]
  pic_000_1549487577_generic_combo_0_crop_002.jpg   green    [good: 0.0,  green: 1.0]
  pic_000_1549487577_generic_combo_0_crop_003.jpg   green    [good: 0.01,  green: 0.99]

To replace a string pattern with empty string in a file

%s/_crop[0-9]*//g

output:
  pic_000_1549487577_generic_combo_0.jpg   green    [good: 0.01,  green: 0.99]
  pic_000_1549487577_generic_combo_0.jpg   green    [good: 0.0,  green: 1.0]
  pic_000_1549487577_generic_combo_0.jpg   green    [good: 0.01,  green: 0.99]


To replace a string from where it matches till the end
%s/\[.*//g

output:
  pic_000_1549487577_generic_combo_0.jpg   green
  pic_000_1549487577_generic_combo_0.jpg   green
  pic_000_1549487577_generic_combo_0.jpg   green

AWK

# awk using multiple delimiters.
example: space and ':'

awk -F'[ :]' '{print $6}' AIreport_classification_combo_labEq_notresized_argmax_count.txt
https://www.tldp.org/LDP/abs/html/comparison-ops.html