The string tag has no wiki summary.
2
votes
1answer
43 views
IPTables string match redirection
The issue: I am currently redirecting port 80 requests to another system on port 1000.
This is done like so:
iptables -t nat -A PREROUTING ! -s 172.20.1.2 -p tcp --dport 80 -j DNAT --to-destination ...
4
votes
2answers
86 views
Convert MAC address to Link-local address with bash
How can I convert a Mac address into an ipv6 Link-Local address?
you have to add fe80:: at the start and insert ff:fe in the middle
furthermore all leading zeros must be stripped
0
votes
2answers
82 views
search fitting ipv6 address for MAC-Address in neighbours
I have a list of possible to ip6 addresses converted MAC-addresses, that could be found in the output of
ping6 ff02::1%wlan0
possible mac addresses are for example:
66:70:02:75:80:fe, ...
2
votes
1answer
65 views
shell parameter substitution to rename files
I need to rename filenames which starts with "foo" into "boo"
This is the script I used
#!/bin/sh
for f in *.jpg;
do
mv -- "{$f}" "${f/foo/boo}";
done
but when i run I get a bad substitution ...
2
votes
2answers
185 views
Testing a string containing only spaces (tabs, or “ ”)?
My code below doesn't work:
stringZ=" "
if [[ "$stringZ" == ^[[:blank:]][[:blank:]]*$ ]];then
echo string is blank
else
echo string is not blank
fi
Result:
string is not blank # wrong
...
2
votes
3answers
1k views
How to get the first word of a string?
When I 'echo *' I get the following output:
file1 file2 file3 ...
What I want is to pick out the first word. How can I proceed?
0
votes
3answers
121 views
Extract the base file name from a URL
url=http://www.foo.bar/file.ext; echo ${url##/*}
I expected this code to print file.ext, but it prints the whole URL. Why? How can I extract the file name?
5
votes
2answers
542 views
Extracting a string, according to a pattern, in a bash script
In bash, suppose that I have a string strname:
strname="ph7go04325r"
I would like to extract the characters between the first "3" character and the last "r" character in strname, saving the result ...
2
votes
5answers
247 views
Test if a string has a period in it with bash
I want to run a bash command on output from Drupal's drush command-line interface. drush site-alias returns a list of webroots, first showing the name of the group, and then each site in that group. ...
10
votes
5answers
390 views
Pattern matching on path names in bash
I want to act on a list of subdirectories in a directory. Consider:
for x in x86-headers/*/C/populate.sh; do echo $x; done
This gives
x86-headers/elf/C/populate.sh
x86-headers/gl/C/populate.sh
...
1
vote
2answers
220 views
Pattern matching from the input arguments
we're trying to enhance the scripts.
Users will pass some arguments and part of the arguments will have 5.0.3 For an example the input argument would be like Jboss5.0.3GA. Since it ( Jboss5.0.3GA ) ...
2
votes
2answers
115 views
Bash variables and types
I'm making a script that validate an IP address. I do this:
read pool
checkIp()
{
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
...
0
votes
1answer
70 views
Alter path of find result [duplicate]
Possible Duplicate:
Manipulate file name piped from find command
How can I alter the path of a file found with find before I run an exec on it? I want to find files and then mv them to a ...
1
vote
2answers
341 views
How to correctly concatenate strings in shells script?
I have a bash shell which I need to modify, and I have to set a variable in a script and then call another script. My variable, EXTRA_JAVA_OPTIONS must be
-javaagent:myagent.jar="-d 0 -i 1000 -l log2 ...
2
votes
2answers
352 views
How to defer variable expansion
I was wanting to initialize some strings at the top of my script with variables that have no yet been set, such as:
str1='I went to ${PLACE} and saw ${EVENT}'
str2='If you do ${ACTION} you will ...
2
votes
3answers
253 views
Search and replacing a string on specific file extensions
I have this bash:
replace="s/AAAA/BBBB/g";
find myDirectory/. -type f -print0 | xargs -0 sed -i $replace;
that will recursively scan myDirectory tree and replace all occurrences of AAAA with ...
2
votes
3answers
209 views
How to reverse-match a string in the Vim programming language?
I want to find the last index of any character in the [abc] set in the abcabc string but the search should start from the end of the string:
" Returns the 0th index but I want the 5th.
let ...
2
votes
2answers
72 views
Filtering the Xth element in a row?
For example, I want to get only the 3rd element in each row when I call:
xinput --list --short|grep "slave pointer"
I get the output:
⎜ ↳ Virtual core XTEST pointer id=4 ...
1
vote
4answers
5k views
Splitting string by the first occurrence of a delimiter
I have a string in the next format
id;some text here with possible ; inside
and want to split it to 2 strings by first occurrence of the ;. So, it should be: id and some text here with possible ; ...
3
votes
1answer
1k views
bash - how to uppercase the command line argument?
I searched SO and found that to uppercase a string following would work
str="Some string"
echo ${str^^}
But I tried to do a similar thing on a command-line argument, which gave me the following ...
1
vote
3answers
2k views
bash string to int
Here is what I tried doing:
#!/bin/sh
res=`df | awk 'FNR == 2 { print $5 }'`
res2=$((res+0))
Here is my error:
-bash: 53%: syntax error: operand expected (error token is "%")
I Googled ...
2
votes
3answers
309 views
Find word in sentence with Bourne Shell (sh)
I'm trying to determine if a particular word appears in a sentence using Bourne Shell (sh). For example:
#!/bin/bash
INPUT='Lorem ipsum dolor sit amet.'
if [[ "$INPUT" == *dolor* ]]
then
echo ...
0
votes
1answer
112 views
awk extended pattern matching (embedding pattern matching in actions for already matched strings) [closed]
I want handle strings of the form:
PREFIX_TYPE_N,DATA
So, does the *awk (gawk, mawk, nawk) support including pattern matching in the action for already matched string? Something like this (of ...
1
vote
4answers
858 views
Appending a string containing escape character with sed
Currently I use:
sed -i -e "5a\\
${text}" $filename
to append something to a certain line, where the variable text
contains a string such as "\epsilon".
When using
echo -E $text
the string is ...
1
vote
1answer
415 views
How to capitalize word (i.e. first letter to upper) in KornShell
Is there a builtin way in KornShell to capitalize a word, e.g. korn -> Korn? A Bash 4 example to clarify:
str='korn'
echo "${str^}"
If there is not a bultin way to do this in KornShell, what is the ...
1
vote
4answers
347 views
Stripping all vowels but the first from a set of strings
I have a string comprised of multiple substrings, separated by underscores. For example: AbcdAEfd_hEgdgE_AbAAAAA. I need to remove all vowels except the first from each substring. So:
AbcdAEfd -> ...
2
votes
2answers
259 views
remove only specific text occurrences from string using sed
I have a text file that contains many rows of this sort of thing:
/*[17:51:27][1 ms]*/ UPDATE `country` SET `region_id` = '4' WHERE `country_id` = '36';
Is there a way that I can use sed to remove ...
3
votes
2answers
241 views
Change string occurrences in file while respecting DOS new line sequences
I use Visual Studio for my C# development while using Cygwin for some of the tasks that require scripting. Recently I wanted to change all occurrences of string AAA to BBB in my project's files. I ...
2
votes
2answers
477 views
How to remove error messages when searching recursively for a string?
I use
find -type f -print0 | xargs -0 -n 10 grep -i searchstring
to search recursively for a string. But it also gives me error messages like "permission denied". How can I avoid such error messages ...
0
votes
1answer
92 views
du (disk usage) and format specifier for file/directory sizes strings?
I am really fond of du, and I often like to use it like this:
$ du -hsc /var/mail/ /var/log/ 2>/dev/null
4,0K /var/mail/
5,7M /var/log/
5,7M total
However, I'd like to be able to ...
5
votes
2answers
607 views
Splitting bash command line argument
Is this the best way to split up a colon separated bash command line argument?
#!/bin/bash
hostlist=`echo $1| awk '{split($0,Ip,":")} END{for (var in Ip) print Ip[var];}'`
for host in $hostlist
do
...
3
votes
4answers
437 views
Replace whole line in a file from command-line
I have a text file which has some contents similar to this:
# General information about the project.
project = u'Py6S'
copyright = u'2012, Robin Wilson'
# The version info for the project you're ...
1
vote
1answer
865 views
How to assign value of variable with regex (bash)?
I want to use regex in bash at line of variable assignment
e.g.
oldip="14\.130\.31\.172"
oldip_a="14.130.31.172" << How to use regex to del all '\'? and assign to oldip_a
Do you have any ...
3
votes
3answers
461 views
Extracting text from a text file in bash
I have a large text file that is all one line. In the text are several sections that looks like foo=12345 and I need to extract them all as separate lines, ignoring the rest of the file.
For ...
1
vote
2answers
132 views
Variable name from command output
I have some string, and want to split on colon ":" assigning on variable with name from left part and value from right part. For example:
echo "Title: Some title" | sed 's/:.*//'
gives me wanted ...
0
votes
2answers
228 views
Checking if PATH contains $HOME/mydir and adding it if not (all in a script) [duplicate]
Possible Duplicate:
keep duplicates out of $PATH on source
I am not an expert with Unix scripting. Some of my scripts are located in $HOME/mydir. Unfortunately, they are not accessible from ...
7
votes
3answers
4k views
Bash - test for newline?
In various places around the web I've found:
\015
\012
\x0a - hex
\n
\r
all as synonyms for various newlines / carriage returns...
But in this small script I cannot recognise when I come across a ...
2
votes
1answer
353 views
Replace complex string in several files
A hacker got into a web server and added this string (removed some characters for security purposes and added line breaks for readability) in all index.php files:
<?php
...
4
votes
3answers
2k views
Most common encoding for strings in C++ in Linux (and Unix?)
For creating a C++ program that is source code level portable between Windows and Linux and handles internationalization well, there are IMHO three main encodings to consider:
The encoding of the ...
2
votes
4answers
225 views
Generate lists of page numbers for 2-up duplex printing: 2,3,… and 1,4,…
How can I generate the following increments?
2,3,6,7,10,11,14,15,18,19,22,23,26,27,30,31,34,35,38,39,42,43,46,47,...,135
and
...
6
votes
7answers
787 views
Bash - Continuous String Manipulation
#!/bin/bash
FILE="$(basename "$1")"
FILE="${FILE/%.jpeg/.jpg}"
Is there anyway to glue these two lines together into a one-liner?
2
votes
3answers
1k views
Bash string replace multiple chars with one
I'm replacing, from a feed title, all chars except letters and digits with a dash to use the result as a safe filename for any filesystem:
$ t="Episodie 06: No hope of riding home (NEW) - Advanced ...
1
vote
1answer
167 views
Check a bash variable against a file
I have a bash variable ($HTTP_COOKIE) which contains a string. I want to check if this string matches the content of a given file (token). I'm working on a busybox linux.
How should I do?
3
votes
3answers
2k views
How to pass a string parameter on bash function?
I have this code that does work:
get_parameter ()
{
echo "$query" | sed -n 's/^.*name=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"
}
But I want to replace the "name" with the parameter that I pass ...
2
votes
3answers
86 views
expr help - managing strings
I need to take text like this:
A234321=http://www.google..... a normal URL
And pull out only the URL, getting rid of the first part. I think I can use expr to do it, but I can't figure out the ...
3
votes
2answers
1k views
grep surrounding characters of a match
I'm looking to do a find and replace within a giant database dump, and it's not doing what I think should happen. I'd like to grep for my target string in the file, and then see the surrounding 8 ...
2
votes
3answers
106 views
How to pass lines from a file to a bash script, so that each line remains undivided, even if there are spaces?
Given:
$ cat lines.txt
a/b
'c/d e/f'
$ cat 1.sh
#!/bin/sh
./2.sh `cat lines.txt`
$ cat 2.sh
#!/bin/sh
echo p1=$1
echo p2=$2
echo p3=$3
$ ./1.sh
p1=a/b
p2='c/d
p3=e/f'
How do I change lines.txt ...
3
votes
2answers
163 views
filename with no spaces from two command lines
I am running two Linux commands and I want to put the resulting values together in a filename with no spaces and a dot separating the two values. So far, I've got this:
pid=`sudo dmidecode -s ...
2
votes
2answers
5k views
Bash shell script to locate and remove substring within a filename
I am trying to write a bash shell script in Mac OS X 10.6 (which is called by an Automator Action) to rename TV show DVD rips that I have named badly over the years. I want to remove part of the text ...
2
votes
1answer
316 views
Need help converting a string from a file into a date
I'm trying to read a string from a file and then convert it into a date but for some reason it's failing. I'm actually modifying a GeekTool Geeklet that's not working at the moment. It reads a file ...