-
Laurent Modolo authoredLaurent Modolo authored
title: Text manipulation
author: "Laurent Modolo"
output:
rmdformats::downcute:
self_contain: true
use_bookdown: true
default_style: "light"
lightbox: true
css: "./www/style_Rmd.css"
if (!require("fontawesome")) {
install.packages("fontawesome")
}
if (!require("klippy")) {
install.packages("remotes")
remotes::install_github("rlesur/klippy")
}
library(fontawesome)
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(comment = NA)
klippy::klippy(
position = c('top', 'right'),
color = "white",
tooltip_message = 'Click to copy',
tooltip_success = 'Copied !')
Batch processing
Objective: Learn basics of batch processing in GNU/Linux
In the previous section, we have seen how to handle streams and text. We can use this knowledge to generate list of command instead of text. This is called batch processing.
In everyday life, you may want to run command sequentiality without using pipes.
To run CMD1
and then run CMD2
you can use the ;
operator
CMD1 ; CMD2
To run CMD1
and then run CMD2
if CMD1
didn’t throw an error, you can use the &&
operator which is safer than the ;
operator.
CMD1 && CMD2
You can also use the ||
to manage errors and run CMD2
if CMD1
failed.
CMD1 || CMD2
Executing list of commands
The easiest option to execute list of command is to use xargs
. xargs
reads arguments from stdin and use them as argument for a command. In UNIX systems the command echo
send string of character into stdout. We are going to use this command to learn more about xargs
.
echo "hello world"
In general a string of character differs from a command when it’s placed between quotes.
The two following commands are equivalent, why ?
echo "file1 file2 file3" | xargs touch
touch file1 file2 file3
You can display the command executed by xargs
with the switch -t
.