Skip to main content

Questions tagged [string]

String manipulation: extracting a part of a string, text replacement, formatting to a given width, etc.

Filter by
Sorted by
Tagged with
2 votes
1 answer
224 views

Joining 'fish shell' arguments into a single string with spaces

Sorry, this question is already answered for 'bash' here: Joining bash arguments into single string with spaces. in Fish, using "'$*'" leads to this error: $* is not supported. In fish, ...
MHM's user avatar
  • 43
0 votes
1 answer
40 views

What does the line ($eachJOBID = $eachScriptNoPath) =~ s/\.csh// ; do?

This line I have in my code cuts the .csh from a string and returns the rest of it. Can someone explain what each part of it does? ($eachJOBID = $eachScriptNoPath) =~ s/\.csh// ;
manylya's user avatar
2 votes
5 answers
130 views

How to remove duplicate slashes from path to a file?

I have a path to a file that has duplicate slashes which would like to simplify. For example, if I have the following: /opt//bin//executable I would like to get: /opt/bin/executable
Thesevs SCUTULATUS's user avatar
-1 votes
1 answer
42 views

I can't grep some inputrc string

bind -p |grep -E "\\e.\":" work but bind -p |grep -E "\\e\\C-.\":" don't work I tried a lot of combination
user3634569's user avatar
1 vote
1 answer
56 views

GNU parallel: how to call exported bash function with empty string argument?

Scenario: $ process(){ echo "[$1] [$2] [$3]" ; } ; export -f process $ process "x" "" "a.txt" [x] [] [a.txt] Here we see that the 2nd argument is empty string ...
pmor's user avatar
  • 629
-1 votes
5 answers
154 views

add empty line before every line that contains certain characters

I have a lot of markdown files that contains something like this: * header A - item 1 - item 2 ** sub-header A1 ** sub-header A2 * header B - item 1 - item 2 ** sub-header B1 ** sub-...
GhostOrder's user avatar
0 votes
0 answers
60 views

Why isn't passed quoted $@ a single argument? [duplicate]

Why isn't passed quoted $@ a single argument? f2() { echo "f2: $1" } f1() { local x=("$@") f2 "${x[@]}" } f1 x y Invocation: $ bash t537.sh f2: ...
pmor's user avatar
  • 629
-1 votes
1 answer
78 views

Checking if I'm correct about the order of operations in Bash

Guten Tag! I'm a rookie in everything Bash-related. I'm familiarizing with the syntax and wanted to know if the order of operations in this command is as I thought or not. The command: echo 2 * 3 > ...
elkronequis's user avatar
2 votes
1 answer
96 views

How to check what character a variable contains and compare it with a number? [closed]

I have an hour record in which subsequent hours are written from 1 to 9 as numbers and then as subsequent alphabetic characters. I would like to save the time in a normal format, so I need to convert ...
pelenex's user avatar
  • 21
0 votes
1 answer
52 views

Retrieve the Following Occurrence of the String 'PWD' Once the Given String is Located

Below is my sample test.log file export SQRDIR=/v/orahome/Middleware/Oracle/bin64 export OID=ap0092 export PWD=pass1 export FDPWD=pass1 export AP0085_PWD=pass1 export SVR=AFFPROD export ...
Ashar's user avatar
  • 511
1 vote
3 answers
349 views

awk print between lines when "/" is part of the name

I need to print lines between those that contain a "/" in the name. I tried with: awk '/+SOLUTION/ESTIMATES/,/-SOLUTION/ESTIMATES/' $F > fil$F and awk '/+SOLUTION"/"ESTIMATES/,/...
euge1780's user avatar
-1 votes
2 answers
458 views

How does the `tr` command work?

I was playing around with tr and got some unexpected results. What is happening in these situations? I don't understand what is happening under the hood, or perhaps I'm not using this command ...
BadHorsie's user avatar
  • 141
1 vote
1 answer
182 views

How to convert all newlines to "\n" in POSIX sh strings

I have a string that contains newline characters. I want to escape all newlines in that string by replacing all newline characters with a string of two characters: "\n". How can I do this in ...
Flux's user avatar
  • 3,038
0 votes
1 answer
584 views

How to remove characters from end of a line till a particular character in perl

my string is like $varin="wer.try.iuy.oiu.qert" i wanted to remove characters starting from end of the string till "." is encountered. expected output: wer.try.iuy.oiu have tried ...
Taylor_Sharma's user avatar
0 votes
0 answers
98 views

Bash reverse search inserting characters into command after hitting tab

SYSTEM: Ubuntu: 20.04 Kernel: 5.4.0-162-generic bash: 5.0.17(1) I found a strange problem that when I use bash's reverse search with CTRL+r, I will find a command I want to run. I select TAB to ...
Dave's user avatar
  • 641
0 votes
1 answer
23 views

Finding on each folder if a subfolder respect the convention name according to the folder name?

i have a "sites" folder with a number of site folder named: bu.my-url.com dud.myurl.com [must-be-indentical_string].myurl.com etc On each site folder, I'd like to check if the /themes/amu_[...
Matoeil's user avatar
  • 103
0 votes
1 answer
358 views

bash: string variable contains asterisk. how to use this variable for searching etc with grep, sed?

Have a nice day I have got text file (zz.txt): Chemical name 3-Aminopropane-1-sulphonic acid Synonym(s) -- Homotaurine * Tramiprosate -- Chemical name Common name and synonyms ... I have variable s=&...
Alex Den's user avatar
1 vote
2 answers
101 views

String Length Always Returns 2 in ZSH Function

I'm trying to bowdlerize email addresses in a fixed length text file by generating a random string the same length as the input. I'm passing the string as a backreference in sed. To simplify, this ...
Paul Joiner's user avatar
0 votes
2 answers
432 views

Use SED to replace part of a current variable with user input variable

I'm trying to replace only part of the existing variable with a new user input variable as below: #Current Variable: gdbName=Test.MY.DOMAIN.COM <--I need to replace the "Test" (This can ...
Ali's user avatar
  • 123
2 votes
2 answers
332 views

extract 2 strings from a log file

I have a log file that gets continuously populated; let's state its name is logfile.txt. In this log file I want to continuously capture sub strings from a single line that contains other strings on ...
guyiom's user avatar
  • 21
2 votes
2 answers
1k views

Tool to flatten yaml

Is there a tool to flatten yaml structure like this: foo: bar: baz: true into this: foo.bar.baz = true not sure what is this syntax name context: I need this for hcl, setting a lot of values ...
Kokizzu's user avatar
  • 10.1k
-4 votes
2 answers
322 views

Is it possible for any shell to interpret a string with decimal point as a number (int, float)?

This idea came to me with recent updates to Visual Studio Code, in which I usually shellcheck my code automatically as well. This is what I see, so you can get the idea: This question is very simple ...
Vlastimil Burián's user avatar
0 votes
1 answer
119 views

Error in chaining multiple conditions inside a single if statement

I am working on a shell script and a part of the script should check if a file doesn't exist or if the filename provided is null (i.e. no filename has been provided). Here is my code - if ! [[ -e &...
hmm-m-m's user avatar
0 votes
0 answers
28 views

How can place a newline before EVERY individual character in a file? [duplicate]

Ok, I may just be having a dumbass moment. If so, I apologize. It sounds like a fairly simple task, but I can't get this working: I'd just like to be able to input a string, and place each individual ...
Lee's user avatar
  • 117
0 votes
4 answers
212 views

How to remove the superfluous "./" from a path?

Consider the following script compare_times.sh (thx to http://superuser.com/a/1780500): #!/bin/bash # Syntax: compare_times.sh directory_1 directory_2 # Semantics: for pairs of files with the same ...
user avatar
0 votes
0 answers
36 views

Comparing a text file's unique content to expected string not registered as equal

I wrote a shell script to check which ".err" text files are empty. Some files have a specific repeated phrase, like this example file fake_error.err (blank lines intentional): WARNING: ...
m13op22's user avatar
  • 101
0 votes
4 answers
751 views

how to print first word from a string with multiple words without space?

I have a shell script to print appimage filenames inside a folder like this #! /bin/bash Dir="$HOME/Applications/" Dir2="$HOME/Downloads/" cd -P "$Dir" for f in *....
Ahmed Moselhi's user avatar
1 vote
1 answer
34 views

Concatenating string passed into a control sequence

I have this echo invocation that prints a blue bar in a Bash terminal: echo $'\e[48;2;0;0;255m \e[0m' I would like to pass some variables to it, something like (this doesn't work): ...
user73235's user avatar
3 votes
1 answer
2k views

How to print leading zeros (padding) in awk?

I am trying to print 99.11111 as 099.11 in AWK. I have tried the following variations without success. $ awk '{printf ("%000.2f\n", $1);}' <<< 99.111111 99.11 $ awk '{printf ("%...
ychaouche's user avatar
  • 1,008
3 votes
1 answer
2k views

Why does escaping double quotes from Python's run (with shell=True) is different than in Bash?

I need to produce JSON configuration files with echo and tee called from my Python script. By trial-and-error I've found out that I have to use single quotes. Yet I don't understand all the behaviour ...
John Smith's user avatar
2 votes
9 answers
2k views

Why grep does not work properly in this case?

Consider a file file2.txt having the following content: P 89 24 -1.5388040474568784e+01 7.4421775186012660e+00 -1.3143195543234219e+03 1.3168884860257754e+03 8.0419002445999993e+01 44 0 0 -97 0 P 122 -...
PhysiXxx's user avatar
  • 227
1 vote
1 answer
47 views

How to extract the following strings from the file?

Consider the following data (say located in file.txt): P 5 24 0 0 -9.0786328019999996e+02 9.1141809916739828e+02 8.0419002445999993e+01 22 0 0 -6 0 P 8 24 -3.9196518724924090e+00 2.0727804903086735e+...
PhysiXxx's user avatar
  • 227
2 votes
1 answer
659 views

Why doesn't ampersand (&) work in string replacement without being escaped?

The following script is really simple, and replaces &amp; with &: string="Foo &amp; Bar" echo "${string//&amp;/&}"; But the script does nothing. There are no ...
IQAndreas's user avatar
  • 10.5k
0 votes
1 answer
389 views

Quoting a string in output from awk

I am fetching a string from a file using awk as shown below. Now I would like to double quote it. Any support would be highly appreciated. awk -F',' '{print $(NF)}' sample.csv| tail +2 output: ...
user3777713's user avatar
3 votes
2 answers
276 views

Bash function colouring from string input matching regex

I have a multi-line string that I use for printing in a bash script. docstring=" Headings -H, -H CNT, -H=CNT, -HCNT, --heading CNT, --heading=CNT Warnings -W, -W CNT, -W=CNT, -WCNT, --...
Vera's user avatar
  • 1
1 vote
2 answers
102 views

Multi-line documentation for bash inspired by lisp

I want to print some usage information for some functions. I customarily use echo or printf for each line. echo "-V, --version" echo " Display the version number and copyrights ...
Vera's user avatar
  • 1
0 votes
0 answers
282 views

How does one store the evaluation of a big string with multiple env variables $VAR into another env variable?

Becuase I need to make sure I run authentication for my nohup commands I need the real command I want to run to be in a string in here: nohup sh -c 'echo $SU_PASSWORD | /afs/cs/software/bin/reauth; ...
Charlie Parker's user avatar
0 votes
1 answer
161 views

how to detect unbalanced special characters in string

I'm wondering what would be the best way (likely using grep or ack) to return lines containing unbalanced special character sets in a string? For example, if the string were: bqM#+t1U"OyBGhk]ozVG[...
irishwristwatch's user avatar
0 votes
0 answers
46 views

Creating a script which compares the return value from an AT command

I am trying to write a shell script that can save the output of a piped process to a variable. This variable is then compared to a known string in order to discern whether or not my AT modem is ...
adamsthename's user avatar
1 vote
3 answers
106 views

get specific output in linux after string

Controller loading lists... ------------------------------------------------- command: select SERVICE_NAME from <table_name> ------------------------------------------------- ...
Leo Shukla's user avatar
2 votes
2 answers
99 views

How do I convert the text to remove words with one letter?

How do I convert the text of the input stream in the following way: skip single letter words. If the word contains one number and one letter, it should also be omitted. I have a Text1.txt file and ...
Denchik's user avatar
  • 21
1 vote
1 answer
350 views

test returns wrong value (but no errors) depending on the presence of spaces around the operator

If there are spaces around the operator, test returns the correct value of the expression. But if there are no spaces, it doesn't throw any syntax error and always return true. $ test "A" == ...
robertspierre's user avatar
0 votes
1 answer
379 views

How can I append a specific text at the end of each line in a file?

I have a file called my_file.txt. Its content is as follows: 7rrmC 7rztC 7s63D 7scfA 7sciA 7seuA 7sh3B 7shgA 7sj9N 7sp5A 7sr2B 7stdC 7sv6A 7sybA 7t2yB 7t30B 7t3bE 7t4rA 7t71A 7t8wD 7tacA 7tbsA 7tfmA ...
user366312's user avatar
1 vote
3 answers
315 views

Extract file length from output of 'ls -l' passed back from sftp session

From my local server I only have access to stfp to a remote server where I want to check the size of my backup file as it's being created. So I've been able to write a bit of bash that logs in and ...
Jock Coats's user avatar
1 vote
1 answer
94 views

How to delete a string in my files?

So I want to match all below then remove those lines of string. [MTT-5634](https://my.atlassian.net/browse/MTT-5634) [MCC-123](https://my.atlassian.net/browse/MCC-123) [MTT-7965]: https://my.atlassian....
Beelzebub's user avatar
4 votes
1 answer
5k views

Convert comma separated string into json array

I have the following string in bash "3.8,3.9,3.10" Is there a way using shell to convert it into a json array, i.e. ["3.8", "3.9", "3.10"]
pkaramol's user avatar
  • 2,949
0 votes
2 answers
233 views

Extract text from first and last strings

I want to extract text from a string matching the first and last word string is a path : /path/to/the/file/app.apk(randomcharacters) and I want to extract text like /path/to/the/file/app.apk using ...
decipher's user avatar
  • 312
3 votes
3 answers
1k views

Extracting json fields in a log line using awk or some other cli tool

Here's the log format in the system that we are currently using and right now it's not easy to change the logs format through the entire system. And I need a way to extract the json object in the logs ...
matrixisreal's user avatar
0 votes
1 answer
97 views

uncomment the line upon search string while ignoring case in a file

Below is my cron file entries: #Ansible: test2 */15 * * * * ansible-playbook /web/playbooks/automation/detect401MORTEN/va_action.yml | tee -a /web/playbooks/automation/detect401MORTEN/cron.out # #...
Ashar's user avatar
  • 511
-1 votes
1 answer
217 views

Why is my file with 10 random bytes larger than 10 bytes?

So I have generated a random string of 10 bytes using the command openssl rand -hex 10 > result. My question is why does the resulting file have a size of 21 bytes? I haven't encrypted so I am not ...
Kobby's user avatar
  • 17

1
2 3 4 5
16