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
-4 votes
5 answers
121 views

I have those lines mycommand --option1 mycommand --option2 mycommand --option3 mycommand --option4 mycommand -h mycommand -i mycommand -z mycommand -1 I want to remove all until - or -- appear so I ...
elbarna's user avatar
  • 14.5k
2 votes
1 answer
83 views

/* ----------------- WANT TO RETURN1 ----------------- */ machine: some value server: WANT TO RETURN1 owner: some value notification: some value informatica: some value sap:...
user9797's user avatar
1 vote
6 answers
734 views

I'm using Debian 12 bookworm, gnu sed. I have this "Hello1" "('41-Z', 5001, 'A6')" "'Hello2'" "('42-Z', 5002, 'A7')" 'Hello3' "('43-Z', 5003, 'A8')" ...
shrykullgod's user avatar
6 votes
2 answers
519 views

The metadata of this file which resides on my HDD is written by CoW, therefore can I look for it just by using grep or strings, and the filename?
user324831's user avatar
0 votes
3 answers
126 views

I have a string of text and spaces which looks like this: macOS windows arch-linux ubuntu_linux I want to append each item (with whitespace denoting a break between items) to a bash array. How do I ...
EmberNeurosis's user avatar
2 votes
1 answer
489 views

This question is similar to this one but it differs from it: Consider this array with string elements which may contain spaces: a@W:$ arr=("eins" "zwei" "eins plus zwei" &...
Adalbert Hanßen's user avatar
-1 votes
2 answers
94 views

Update: Up to 2 "/" in the string. String structure is either: Character set name/LF Character set name/CRLF Character set name/CRLF/(unknown purpose, likely a number) Character set name ...
strider's user avatar
  • 113
0 votes
2 answers
256 views

I'm trying to check if the value inside a file is "0". COUNT_EXECUTION=$(< /tmp/count) if [ "$COUNT_EXECUTION" == "0" ]; then echo "Try restart service." ...
Aderbal Nunes's user avatar
0 votes
3 answers
336 views

I need to edit the string "NA" to "Na" only if it is in the 6th field of a file. I can currently achieve this with: awk '{gsub("NA","Na",$6)}1' $filename ...
CPC_92's user avatar
  • 3
0 votes
3 answers
436 views

I have a json object that has an unknown number of variables, like this: { "var1": 123, "var2": 456, "var3": 789 } How can I automatically convert it to form ...
teeeeee's user avatar
  • 305
0 votes
1 answer
119 views

I have a script that kicks off a new terminal window that I want to move to a specific position on the left terminal using xdotool. After kicking off the terminal I run xdotool search --class gnome-...
Tex's user avatar
  • 1
2 votes
1 answer
356 views

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
  • 83
0 votes
1 answer
68 views

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
611 views

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
66 views

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
108 views

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
  • 757
-1 votes
5 answers
229 views

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
63 views

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
  • 757
-1 votes
1 answer
166 views

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
191 views

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
70 views

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
  • 527
1 vote
3 answers
404 views

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
7k views

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
328 views

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,318
0 votes
1 answer
1k views

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
167 views

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
  • 732
0 votes
1 answer
35 views

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
675 views

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
183 views

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
613 views

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
428 views

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
2k views

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.6k
-4 votes
2 answers
512 views

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
257 views

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
32 views

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
  • 135
0 votes
4 answers
284 views

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
58 views

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
930 views

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
50 views

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

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,043
3 votes
1 answer
3k views

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

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
60 views

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
3 votes
1 answer
1k views

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.7k
1 vote
1 answer
1k views

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
437 views

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,373
1 vote
2 answers
138 views

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,373
0 votes
0 answers
314 views

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
273 views

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
110 views

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
2 3 4 5
17