Questions tagged [strings]

31 questions
50
votes
5 answers

Linux Command to find Strings in Binary or non ascii file

Is there any linux command to extracts all the ascii strings from an executable or other binary file? I suppose I could do it with a grep, but I remember hearing somewhere that such a command existed?
Ethan Heilman
  • 711
  • 2
  • 8
  • 10
20
votes
4 answers

Linux shell command to filter a text file by line length

I have a 30gb disk image of a borked partition (think dd if=/dev/sda1 of=diskimage) that I need to recover some text files from. Data carving tools like foremost only work on files with well defined headers, i.e. not plain text files, so I've fallen…
Li-aung Yip
  • 413
  • 1
  • 4
  • 9
16
votes
8 answers

Extract repository name from GitHub url in bash

Given ANY GitHub repository url string like: git://github.com/some-user/my-repo.git or git@github.com:some-user/my-repo.git or https://github.com/some-user/my-repo.git What is the best way in bash to extract the repository name my-repo from any…
Justin
  • 5,008
  • 19
  • 58
  • 82
16
votes
7 answers

portable unix way to join strings with separator

Is there a portable unix shellscripting way of joining a number of strings together with a given separator, like so: $ strjoin --- foo bar baz quux foo---bar---baz---quux Sure I could use a $scripting_language one liner or an ugly explicit loop in…
JanKanis
  • 473
  • 1
  • 5
  • 11
12
votes
2 answers

How to get lines that contain string in a file?

In Linux, How do I display lines that contain a string in a text file, such as: search "my string" file_name How do I make the search case sensitive/insensitive? And how do I also display the line numbers? Regards
alwbtc
  • 229
  • 1
  • 4
  • 7
7
votes
2 answers

Lowercase variable values in a Puppet template

In my puppet config I need to lowercase a variable value before using it in a template. How to achieve this? Is there a way to lowercase a variable value inside the puppet manifest? Do I need to do this in the template? And more general: where are…
paweloque
  • 257
  • 1
  • 4
  • 10
7
votes
5 answers

How do I split a string against a character in BASH?

I would like to be able to split an authorization code by the - character so that I can operate on each segment individually. I do not want to use external binaries (awk, grep) - this is to be as minimalistic as possible. What are some ways I can…
Jay Hellwig
  • 73
  • 1
  • 5
6
votes
3 answers

How to reset a tcp connection immediately on both ends on a certain condition using linux netfilter/iptables?

Dear Serverfault community, I have the following problem: I need to reset (disconnect) tcp connections on both network sides immediately if a certain string is encountered in the packet data. I don't have control over the applications on both sides…
Jens Moser
  • 83
  • 2
  • 6
6
votes
2 answers

How do I get the last part of directory from a command line

How do I store the last part of directory in a variable? For example I have the following path: A\B\C\D, I want to store D in variable like file_name=D.
Mohammad AL-Rawabdeh
  • 1,592
  • 12
  • 30
  • 54
4
votes
3 answers

Replacing a string in an XML with Powershell causes MALFORMED XML

I have a rather large XML file that I need to replace some connection strings within. I use the following code to replace the strings: $temp = Get-Content .\bigxmlfile.xml $temp.replace("STRING1","STRING2") | out-file .\bigxmlfile.xml -force This…
JustAGuy
  • 629
  • 3
  • 18
  • 35
4
votes
1 answer

How to add an event/alert on Zenoss for a string type SNMP OID?

I have the status of a particular application being reported as string over SNMP. When everything is working as expected, that monitoring reports an empty string and when some of the data sources have problems, it reports back an string with the…
Carlos Lima
  • 475
  • 3
  • 11
3
votes
5 answers

Strip a single line out of many files

I am trying to remove a string from many text files on one of our servers. The string is identical across all these files and I can run: grep -r -l 'string' to get the file list but I am stuck on how to get the files edited and written out to…
Manny T
  • 68
  • 1
  • 6
3
votes
6 answers

How to replace a text string in multiple files in Linux

There are a variety of ways to replace one string of text with another across many files. Here are a few ways: using sed and find: sed 's/oldstring/newstring/' "$1" > "$1".new && find -iname "*.new" | sed 's/.new//' | sh using grep and sed: grep…
Ali Mezgani
  • 3,810
  • 2
  • 23
  • 36
3
votes
4 answers

How to extract hostname from $(who am i)

I try to extract the hostname from the following string (created using who am i): username pts/0 2010-10-05 17:30 (www.example.com) I need a solution which also works if (www.example.com) is not present which is the case when I am logged in…
t6d
  • 507
  • 2
  • 5
  • 12
3
votes
1 answer

problem with strings in script powershell sudo

im making a script like sudo, the idea is that the sudo function is going to run a scriptblock in elevation. I'm having trouble with the strings variables, that i pass in that scriptblock. Is like the doubles quotes disappear. What is wrong with my…
mjsr
  • 181
  • 7
1
2 3