New answers tagged string
2
votes
awk print between lines when "/" is part of the name
/regex/ is short for $0 ~ /regex/, which you can also write $0 ~ "regex", so besides escaping the / by prefixing it with \ or using \octal with the / character value (\57 on ASCII-based ...
2
votes
awk print between lines when "/" is part of the name
How can I print lines between those patterns?
By replacing / with \57 records between patterns (and records with those patterns) can be printed.
But please read this before using range expressions.
$ ...
1
vote
Accepted
awk print between lines when "/" is part of the name
When used inside an awk regular expression constant, the forward slash character must be escaped to distinguish it from the surrounding delimiters. For example with GNU awk:
$ echo 'foo/bar was here' |...
3
votes
Accepted
How does the `tr` command work?
tr’s arguments are maps of characters: characters are mapped 1:1 in order. In the set of replacements, the last character is repeated as necessary; extra characters are ignored.
Thus
tr 5 x
replaces ‘...
1
vote
How does the `tr` command work?
IMO this behavior is explained perfectly in the macos tr man page:
In the first synopsis form, the characters in string1 are translated into the characters in string2 where the first character in ...
1
vote
Accepted
How to convert all newlines to "\n" in POSIX sh strings
Try awk with:
string='x
y
'
new_string=$(
LC_ALL=C awk -- '
BEGIN {
gsub("\n", "\\n", ARGV[1])
printf "%s", ARGV[1]
}' "$string"
)
In any ...
0
votes
How to reverse a string made of digit in bash?
Given:
$ echo "$s"
12345
6789
Here is a Ruby that reverses each line of input:
$ echo "$s" | ruby -lpe '$_=$_.reverse'
54321
9876
Top 50 recent answers are included
Related Tags
string × 790bash × 317
shell-script × 168
sed × 122
shell × 118
grep × 89
awk × 88
text-processing × 71
regular-expression × 52
linux × 49
search × 46
variable × 41
replace × 38
files × 34
scripting × 30
array × 26
zsh × 25
filenames × 24
command-line × 21
find × 19
test × 18
quoting × 17
cut × 13
date × 12
wildcards × 12