Linked Questions

-2 votes
1 answer
5k views

BASH: Get text before string [duplicate]

how to get text before a delimeter string in Bash? Like: str="Hello World! It's a nice Day!" i need to get everything before nice. echo $str should show me Hello World! It's a Thank you
Chris's user avatar
  • 456
0 votes
2 answers
2k views

how to delete string from a particular text to end of line? [duplicate]

For example, if there is: hello(abcdef) = 3 good(adss) = 5 then I have to replace these into: hello good Thus I need to delete each line from '(' to right '\n' and replate these into '\n' Is is ...
sungjun cho's user avatar
1 vote
2 answers
1k views

Removing everything after last hyphen in a string in Bash script? [duplicate]

Working on a script where I need to take a string, and remove everything after the last occurence of a certain character. In this case a hyphen. For example, This-is-a-filename-0001.jpg should result ...
Benjamin Allison's user avatar
-4 votes
4 answers
277 views

how to extract multiple lines between header and footer in bash [duplicate]

if I have a bash variable that contains the following string: my signed 1.5 tag -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAABAgAGBQJTZbQlAAoJEF0+sviABDDrZbQH/09PfE51KPVPlanr6q1v4/Ut ...
matthias_buehlmann's user avatar
0 votes
1 answer
101 views

How do i remove slashes in mkdir command? [duplicate]

As you know, you cannot use the mkdir command with slashes. I am creating an automation and what i did first, was to nmap every IP Addresses i chose, "192.168.1.0" for example, as the first ...
Oded's user avatar
  • 13
0 votes
0 answers
49 views

is it possible to trim my sed in easier way to get the output? [duplicate]

In one of my use case, required to trim the needed prefix by using below sed command. just curious to know is there any way to reduce the sed command (i mean simpler way instead of having long trim :) ...
Velu's user avatar
  • 23
0 votes
0 answers
39 views

How to remove all symbols after dot [duplicate]

For example I have IP addresses list 192.168.20.5 192.168.20.12 192.168.20.141 How to remove all symbols after last dot and get this list (below) at the output 192.168.20. 192.168.20. 192.168.20. ...
user avatar
0 votes
0 answers
37 views

How do you remove a section of of a file name after underscore including the underscore using bash? [duplicate]

We regularly have images that are named 1234567890_GH_ANI_EPS.eps with variables after the first underscore. I would like to write a bash script to remove the first underscore up to the file extension....
djoins's user avatar
  • 15
3 votes
4 answers
7k views

Deleting string up to the first occurrence of certain character

Is there a way to delete all the characters up to and including the first occurrence of a certain character? 123:abc 12:cba 1234:cccc and the output would be: abc cba cccc
Rok Dolinar's user avatar
0 votes
4 answers
285 views

How to delete all text on a line appearing after a particular symbol?

I have a file, file1.txt, like this: This is some text. This is some more text. ② This is a note. This is yet some more text. I need to delete any text appearing after "②", including the "②" and any ...
Village's user avatar
  • 23.9k
1 vote
2 answers
209 views

Bash - Remove all text after characters using wildcards

I saw this SO answer showing how you can remove all text after a character in a string in Bash. With this information, I can do something like this to round down a number: NUMBER=10.12345 NUMBER=${...
APixel Visuals's user avatar
2 votes
1 answer
1k views

Remove slash from ip/block address and place ip and block in a variable [duplicate]

I am trying to separate the ip/block address and place the ip in a variable and the block in another. This is what I have so far. #!/bin/bash ipblock="100.100.40.160/29" block="$(basename $ipblock)" ...
Vituvo's user avatar
  • 1,038
2 votes
2 answers
362 views

Bash script to run diff command on files in two directories and provide custom side by side output?

EDIT - Reproducible Code, Output, and Updated Question #!/bin/bash # Input Directory inpd="/home/space user/space test/space dir1" # Line To Parse line="/home/space user/space test/...
SystemTheory's user avatar
1 vote
3 answers
386 views

Find directories where a text is found in a specific file

How can I find the directories where a text is found in a specific file? E.g. I want to get all the directories in "/var/www/" that contain the text "foo-bundle" in the composer....
Manolo's user avatar
  • 25.6k
-1 votes
1 answer
53 views

Why does cut not work with the output of a program? [duplicate]

I need to get the version number of a program from the following output: ~$ pyrcc5 -version pyrcc5 v5.15.0 ~$ Now I thought cut could do the job: ~$ pyrcc5 -version | cut -f2 -d"v" pyrcc5 ...
TheEagle's user avatar
  • 5,914

15 30 50 per page