0
votes
2answers
33 views

Why does this bash command sometimes return a blank string?

I have the following line to generate a random number: head -c 3 /dev/urandom | hexdump | sed -e 's/[0 a-z]//g' | head -c 1 This works fine but sometimes (very few) it returns a new line. Does ...
0
votes
2answers
27 views

Tinydns data file change ip with bash

I am using tinydns and need to dynamicly change some ip in data file. I want to use bash script for it. For example data file: +sub1.example.org:282.196.222.245:14400 ...
1
vote
1answer
57 views

Wrangling sed to find and reformat login date (or, how to kill idle mosh-server processes)

I have an old method of killing idle mosh-server processes, which doesn't work on my new VPS. Here's the old method, which I run in root's crontab to clean up mosh processes that have been idle for ...
1
vote
2answers
62 views

Long string insertion with sed

I am trying to use this expression to insert the contents of one text file into another after a give string. This is a simple bash script: TEXT=`cat file1.txt` sed -i "/teststring/a \ ...
1
vote
2answers
46 views

I want to filter out two lines from the output of a program [closed]

I have a command that outputs a bunch of data, but I only want two lines. Grep doesn't work because the lines I want are not next to one another. I can't seem to figure out sed... Help please. :) ...
2
votes
2answers
1k views

Using sed to remove both an opening and closing square bracket around a string

I'm running this command in a bash shell on Ubuntu 12.04.1 LTS. I'm attempting to remove both the [ and ] characters in one fell swoop, i.e. without having to pipe to sed a second time. I know square ...
0
votes
1answer
68 views

Remove all words that DOESN'T contain a colon [closed]

I have a file with this type of lines: blabla bla:bla whatever what:ever alpha bravo charlie del:ta I only want to keep the words that contain a colon. So the output for the above would be: ...
2
votes
3answers
961 views

How can I easily convert HTML special entities from a standard input stream in Linux?

CentOS Is there an easy way to convert HTML special entities from a data stream? I'm passing data to a bash script and sometimes that data includes special entities. For example: "test" ...
0
votes
1answer
91 views

script for changing file dates of postfix Mailbox files

I have a Maildir structure, that got wrongly restored from backup and all files have the file date of the restore instead of when they have been created/received. What would be the best way to ...
1
vote
1answer
2k views

sed replace all tabs and spaces with a single space

I got a string like the following: test.de. 1547 IN SOA ns1.test.de. dnsmaster.test.de. 2012090701 900 1000 6000 600 now I want to replace all the tabs/spaces inbetween the ...
2
votes
2answers
817 views

How can I add a line break before a set of values going into a bash script?

I've got a set of data piping into a bash script. Here's an example of what that data looks like: "foo1": "Miscellaneous text", "foo2": "More text", "foo3": "blah blah blah", "foo4": ...
0
votes
1answer
133 views

Replace Javascript malware code with empty string [duplicate]

Possible Duplicate: My server's been hacked EMERGENCY I have following code in hundreds of my html and js files: ...
7
votes
2answers
725 views

bash sub-string extraction for specified start and end character

For example I have a log file having this entry: [Wed Aug 08 11:39:41 2012] [error] [client 155.94.70.224] ModSecurity: [file ...
1
vote
1answer
122 views

sed replace inside shell file

I have a shell file which needs to perform a replace of some text in a php file. The line that needs replacing is: $database = $db."_db"; The actual sed command needs to contain a variable so not ...
0
votes
3answers
170 views

How to join a variable number of lines

I have a file with Feature names and a variable number of usernames below: Feature1 user1 user2 Feature2 user3 I'd like to be able to move the usernames to the same line as the Feature name ...
2
votes
2answers
419 views

sed: how to insert a comment at the beginning of a matching line

I am attempting to write a script that will comment out the following line in /etc/sudoers every time I launch a new EC2 instance: Defaults requiretty I'm assuming the best way to do this is with ...
1
vote
3answers
306 views

sed not working in linux centos, ubuntu,

I have a simple script that gives me some values from a file. I am using sed to get that vaules (syntax is given below). these commands were working fine till yesterday. but now I'm not getting any ...
0
votes
1answer
149 views

cutting relevant portions of a file [closed]

I want to cut some portions of binary file starting from a particular pattern and ending at a particular pattern.How do I do that in linux using bash.Can this be done using sed or awk? I have a file ...
17
votes
6answers
4k views

bash/sed/awk/etc remove every other newline

a bash commands outputs this: Runtime Name: vmhba2:C0:T3:L14 Group State: active Runtime Name: vmhba3:C0:T0:L14 Group State: active unoptimized Runtime Name: vmhba2:C0:T1:L14 Group State: active ...
0
votes
1answer
137 views

sed search replace enrypted string range [duplicate]

Possible Duplicate: My server's been hacked EMERGENCY my php based website got infected with malware, which added something like this in the code: <?php ...
2
votes
2answers
387 views

Prefix standard output before piping to a command

On Linux (Debian), how can I prefix the standard output of a command with one or several lines before piping it to a second command? This is for mailing the output of a command using sendmail like ...
0
votes
1answer
752 views

llinux - replace subnet mask in ifcfg-eth0 with sed or awk

I have 30 linux servers that I need to change subnetmask. I want to use a simple script or a simple command to change the subnemt mask from 255.255.255.128 to 255.255.255.0 in ifcfg-eth0. can ...
4
votes
4answers
4k views

Parse and convert ini into bash array variables

I'm trying to convert an ini file into bash array variables. The sample ini is as below [foobar] session=foo path=/some/path [barfoo] session=bar path=/some/path so these become ...
0
votes
1answer
79 views

Parse value of $DatabasePassword from RT_SiteConfig.pm

I'm writing a Bash shell script to backup our Request Tracker (RT) MySQL database on a daily basis. Instead of hard-coding the MySQL database user's password in the shell script I'd like to parse it ...
4
votes
3answers
4k views

Regex for sed to grab multiple lines or a better way?

I'm creating a script that connects to a server and dumps the output to a tempfile. I want to use sed in the script to grab specific information from the temp file. The output would always have the 80 ...
2
votes
1answer
964 views

problem executing a bash script with utf8 encoding

I have a bash script encoded in utf8 . Within the script i use sed command using ยง as a separator . Now when i run execute this script sed complains about the separator. If i use normal char as a ...
1
vote
2answers
135 views

Using SED to update .htaccess with blocked IP addresses

I have a file that has a list of "bad" IP addresses. I want to import this file of bad IP addresses into my .htaccess file to deny access via apache. I want to automate this process using sed. How ...
1
vote
4answers
647 views

Bash: delete all but most recent n files with prefix x

I have a directory of backups that looks like this: -rw-r--r-- 1 ftpuser ftponly 5610595 May 27 00:01 alpha-114.tar.asc -rw-r--r-- 1 ftpuser ftponly 50559368 May 27 00:04 beta-211.tar.asc ...
4
votes
3answers
1k views

SED replace across multiple lines

I am trying to find these three lines: <!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> --> and replace them with: <Connector port="8009" protocol="AJP/1.3" ...
2
votes
2answers
158 views

Sed in Bash Difficult pattern

I have a complicated string that I need to search for and replace I need to replace: ...
2
votes
2answers
2k views

Permission Denied when using Sed

I am using Sed to find and replace a string in a file. This is the first time working with it so I maybe doing it wrong, I have a file thats owned by "root" called "test.properties" and I want to ...
0
votes
5answers
158 views

Sed regexp /d deleting whole file

Given a typical known_hosts file: [123.45.67.89]:22 ssh-rsa bbuivvhbkbjdnflksndkfnksnfk... [98.76.54.32]:14444 ssh-rsa hohdibsodbfoasbfbsabdfbsd... [77.34.122.33]:32209 ssh-rsa ...
1
vote
2answers
1k views

Recursively rename files using find and sed

I want to go through a bunch of directories and rename all files that end in _test.rb to end in _spec.rb instead. It's something I've never quite figured out how to do with bash so this time I thought ...
1
vote
1answer
81 views

sed with several matches

The two "sed lines" only differ by a "\n" below.. How can i get this output [no new line before the </pre>]? [ http://pastebin.com/raw.php?i=ED34jvtF ]: . . something3 </pre> something4 . ...
0
votes
1answer
635 views

Using #!/bin/bash script

I am trying to develop a script that will automate setting up a new virtual hosting domain on my server, I have a custom setup on my server that gives every domain a username and password but no shell ...
3
votes
4answers
714 views

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

shell script to iterate through text files and delete a string

I have a few hundred text files in one directory with lists of users: &usera &userb userc &userd note that some do not lead with the &. Also, in some files, the last line does not ...
3
votes
2answers
414 views

How do I prevent bash $ substitution?

I'm trying to preserve $if below and would like the following to output $if bash is getting in the way by doing $ substitution $ sed -e 's:\\$:\\$:g' <<ENDOFFILE > $if > ...
4
votes
6answers
2k views

How to remove a tagged block of text in a file?

How can I remove all instances of tagged blocks of text in a file with sed, grep, or another program? If I have a file which contains: random text // START TEXT internal text // ...
4
votes
5answers
1k views

Is it worth while to learn Awk?

I am decent with bash scripting and I am catching on to regex, and a little sed usage. Is learning awk still worth while with all the alternatives out there. Opinions?
0
votes
1answer
726 views

Cannot cd to parent directory with cd dirname

I have made a bash command which generates a one liner for restarting all Weblogic ( 8,9,10) instances on a server. The script works well but I need a suggestion to make it better using the dirname ...
1
vote
2answers
764 views

sed php.ini memory_limit

The following works great: phpmemory_limit=256M #or what ever you want it set to sed -i 's/memory_limit = 16M/memory_limit = '${phpmemory_limit}'/' /etc/php5/apache2/php.ini If the memory_limit is ...
0
votes
2answers
179 views

How can I echo changes made in a sed expression to the console?

I have a simple sed expression: sed -i 's/foo/bar/g' blat.xml Because the expression modifies the file in place it is hard to see which lines were changed. Is there a way to echo the modified ...
1
vote
5answers
978 views

bash script - print from line N to EOF

I want to be able to print the number of lines from bash as such: Line number (as counted from the top) -> end of the file It seems tail will only count lines from the bottom. Does anyone know how ...