Tagged Questions
1
vote
3answers
67 views
sed - how to replace a single quote?
This works fine:
sed -i 's# @driver.find_element(:xpath, "//a\[contains(@href,##' temp_spec.rb
against a source of
@driver.find_element(:xpath, "//a[contains(@href,'change_district')]").click
...
4
votes
4answers
102 views
sed how to substitute when string has “http://” in it?
I have a file xx that has the following contents:
@base_url = "http://dmstaffing-stage.herokuapp.com/"
I want to use sed to eliminate this line (replace with nothing). I have used this sed ...
3
votes
4answers
102 views
Replacing pattern after nth match is found on each line?
I have a file containing lines:
india;austria;japan;chile
china;US;nigeria;mexico;russia
I want to replace all the occurences of semicolon on each line with e.g. ;NEW;, but starting from the 2nd ...
0
votes
0answers
47 views
how to parse this data and count the matching patterns? [closed]
Gi1/0/12
Gi1/0/13
Gi1/0/14
Gi1/0/15
Gi1/0/16
Gi1/0/17
Gi1/0/18
Gi1/0/19
Gi1/0/20
Gi1/0/21
Gi1/0/22
Gi1/0/23
Fa2/0/13
Fa2/0/14
Fa2/0/15
Fa2/0/16
Fa2/0/17
Fa2/0/18
Fa2/0/19
Fa2/0/20
Fa2/0/21
Fa2/0/22
...
1
vote
4answers
67 views
How to find what device a file is on (and use that in a script)?
I want to find out what device my file is on so that I can use it in a script. I can get this far:
$ df .
Filesystem 512-blocks Used Available Capacity Mounted on
/dev/disk0s2 498438976 ...
0
votes
1answer
89 views
How to delete number of lines from file repetitively
I've read How do I delete the first n lines of an ascii file using shell commands?, it is helpful. However I've a file something as below (please consider 2 columns as 2 different files):
1 4
1 4
1 4
...
1
vote
4answers
395 views
How to rename files with sed and csv
I'm new with Linux, sed, and awk but I don't mind challenging myself on new ideas. That being said, I understand the purpose and how to use rename and sed for a common event such as adding a $date or ...
7
votes
10answers
505 views
What's a good way to filter a text file to remove empty lines?
I have a .csv file (on a mac) that has a bunch of empty lines, e.g.:
"1", "2", "lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum ...
1
vote
2answers
134 views
How can I find matches with sed (or similar) for configuration parameters?
I'm pretty good at using php's preg_match (and similar) commands, and I'm also pretty good with regular expressions, but I don't do very well with sed.
I have two shell scripts I'm working on and I'd ...
3
votes
2answers
152 views
Colorizing tail output with sed
How would I go about colorizing the output of tail with sed?
echo "`tput setaf 1`foo`tput op`" works as expected
echo "foo" | sed -e 's/(foo)/`tput setaf 1`\0`tput op`/g' however, does not.
What am ...
1
vote
2answers
135 views
Complicated variable content failed to get into sed
The first line is variable ann hold quite complicated value. The reason I use the second line is because I don't want to change anything in the third line col1content. To change replacement, I just ...
1
vote
2answers
160 views
Substitute pattern within a file with the content of other file
I have a text file (devel.xml).
I added the word REPLACETHIS to it in order to replace this string with the content within a different file (temp.txt).
The closest thing I have is this:
sed -i -e ...
5
votes
3answers
370 views
How to embed a shell command into a sed expression?
I have a text file with the following format:
keyword value
keyword value
...
Where keyword is a single word and value is everything else until the end of line. I want to read the file from a shell ...
1
vote
2answers
306 views
Parsing the output of date with sed
I am trying to replace the whitespaces in the output of date with '_' with no success.
$date
Fri Sep 14 14:10:04 EDT 2012
$ date | sed 's/ /_/'
Fri_Sep 14 14:10:24 EDT 2012
As you can see, the ...
2
votes
2answers
183 views
Piping paths with different types of quotes for slash substitution
I would like to use sed to convert a path with backslashes to the same path with forward slashes:
E.g.
I would like to pipe \\path\to\file\ and obtain /path/to/file
None of the following commands ...
3
votes
2answers
341 views
What is the best way to find a list of several strings within a large text file
The short, general question is: In Unix/Linux, what is the best way to find a list of several (about 150) strings within a large text file?
I am asking this to all Unix/Linux experts as a general ...
4
votes
2answers
587 views
delete first line of file only if blank using sed
I have a solution for this in awk:
awk '{if (NR==1 && NF==0) next};1' somefile
but was unable to find one that worked in sed. E.g.,
sed -i.bak '/^$/{1,1d;}' somefile
ended up deleting ...
3
votes
2answers
223 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
249 views
Detect pattern repetition in a file
I want to make sure a file follows the following pattern:
... ... ... foo ... foo_KO ... ...
... bar ... ... ... ... bar_KO ...
The file is extremely long, so, in other words, I want to make sure ...
9
votes
3answers
766 views
Substituting strings in a very large file
I have a very long series of urls with no separating character, in the same format as below:
http://example.comhttp://example.nethttp://example.orghttp://etc...
I want each URL to be on a new line. ...
3
votes
2answers
286 views
How to skip file in sed if it contains regex?
I currently use the following simplified command to remove trailing whitespace and add a newline at end of file where needed:
find . -type f -exec sed -i -e 's/[ \t]\+\(\r\?\)$/\1/;$a\' {} \+
As ...
1
vote
2answers
382 views
To pass a parameter with sed
For my script I have to read the data from a file.
For example I have 2 files: one is a text file, the second is a csv file with 10 columns.
What I am trying to do is to read the csv and change the ...
0
votes
3answers
501 views
What is the purpose of -e in sed command?
I can't find any documentation about the sed -e switch, for simple replace, do I need it?
e.g.
sed 's/foo/bar/'
VS
sed -e 's/foo/bar/'
3
votes
2answers
5k views
Removing all spaces, tabs, newlines, etc from a variable?
This is the error I am getting and it's failing because of a variable whose value is supposed to be 2 (I am getting this using a select * from tabel).
I am getting spaces in that variable.
+ 0 !=
...
2
votes
4answers
1k views
Using sed to convert newlines into spaces
Say I have a shell variable $string that holds some text with several newlines, e.g.:
string="this
is
a test"
I would like to convert this string into a new string new_string where all line breaks ...
4
votes
4answers
515 views
How to echo an escaped string
How can I echo an escaped string that contains $ in Bourne Shell?
user@server:~$ cat test.sh
#!/bin/sh
echo $1
user@server:~$ ./test.sh \$sad\$test
$sad$test
I want it to return an escaped ...
3
votes
1answer
496 views
Chinese characters instead of Latin being written to file
When I run sed like this and print to a console everything is fine:
sed '/Q/{
s/Q//g
r /Users/ericbrotto/Desktop/question.txt
}' Commision.txt
But when I do this and output t a file:
sed '/Q/{
...
3
votes
4answers
585 views
Replacing text from a list of replacements. Added complication: backslashes
I have a file A that contains pairs of strings, one per line:
\old1 \new1
\old2 \new2
.....
I would like to iterate over file A, and for each line perform the replacement (e.g. "\old1 -> \new1") ...
5
votes
3answers
3k views
Processing bash variable with sed
Been banging my head off a wall on this
bash variable LATLNG contains a latitude & longitude value in brackets like so
(53.3096,-6.28396)
I want to parse these into a variable called LAT and ...
5
votes
4answers
209 views
How could I simplify this command to only use awk?
awk '/user/ {print $1 }' /etc/userdomains | sed 's/://'
the format of /etc/userdomains is
domain.tld: user
otherdomain.tld: otheruser
1
vote
3answers
192 views
Directory filenames with sed with whitespaces
I'm working on a script and I'm stuck, even with the help of teh googles.
Here's my code:
for FOLDER in `find . -type d | sed "s#^.#$(pwd)#" | sed 's/ /\ /g'`
do
echo "$FOLDER"
done
This will ...