4
votes
2answers
38 views

shell script to replace a keyword in a file with the contents of another file

I'm to create a .sh to replace a specific keyword in a file using the contents of an other file. template.html contains a unique string "PLACEHOLDER" it must be replaced with the contents of file ...
0
votes
1answer
27 views

Sed is not Interpreting Pipes Correctly

OK, this is hard to explain, so I will give a reproducible example: I have a text file test.txt contains the line: somesetting-parameter /an/old/path I want to replace it with a path I can get via ...
-2
votes
2answers
49 views

Trying to count and print song file names using awk

RANK NAME BAND YEAR GENERE DOMESTIC/INTERNATIONAL 206:Reach Out, I'll Be There:The Four Tops:1978:Pop:3/2 207:Bye Bye Love:The Everly Brothers:1950:Classic:3/2 ...
1
vote
1answer
25 views

Is it possible to sed -i from a text file to another text file?

I'm coding a shell script on my Debian box and there's a line on the script that needs to delete some emails from a textfile that is full of emails, like this: sed -i ...
2
votes
4answers
553 views

Bash script, string not replaced correctly with escaped $ and & characters

I have created a shell script which takes a string as input. If the string contains $ or &, then I need to replace those characters with \$ and \&. I could done that with sed command. After ...
0
votes
1answer
101 views

Find number in string and replace it

I wrote C++ code and now I want to replace the number in a string by using shell scripts. The part that needs to be replaced: if (random<=90) How I can change the 90 from a shell script? I ...
0
votes
2answers
117 views

split a textfile after each n matches to a new file using sed or awk

i tried to split a file in parts of n matches each. The file is just one line and the seperator is '<br>' foo<br>bar<br>.....<br> I just want to split the file in parts, ...
0
votes
1answer
100 views

Counting by number of occurrences in first column

I have an input file like this: ATTACK-RESPONSES id check returned root BACKDOOR ACKcmdC trojan scan BACKDOOR hack-a-tack attempt BACKDOOR WinCrash 1.0 Server Active ICMP Destination Unreachable ...
1
vote
1answer
200 views

error occur when i run awk command write in .sh file and run in cygwin terminal

i have cygwin terminal for run shell script(.sh ) file...it work good..but when i add awk command in shell script and then run Error occur /usr/bin/gawk.exe: error while loading shared libraries: ...
3
votes
2answers
1k views

SED: How can I print every line after first instance of string using Sed?

I have a file with a similar format... 16:28 asdfasdf 16:29 4398upte 16:30 34liuthr 16:31 34tertio How can I use SED to print out every line including and after the line with "16:30"? The result ...
1
vote
1answer
207 views

Subtract files from one another recursively between two similar directories

I'm trying to concoct a way to grab two (nearly identical) directories and show me the difference between all files in the two directories. Looking for two different things: 1- List all files ...
0
votes
1answer
475 views

Grep issue (match two strings on same line)

Here I have some grep command which is not working correctly: cat file1.txt: apples Date: Sun, 24 Feb 2013 8:14:06 -0800 peaches melons cherry sky cloud green purple yellow cat file2.txt: apples ...
0
votes
1answer
254 views

Combining multiple data files with header while also adding a data column

I have multiple tab delimited data files that are separated by month in the format jan06.txt, feb06.txt, ..., dec07.txt. Within each file, it looks something like: Header1 Header2 Header3 ... Data1 ...
0
votes
3answers
426 views

Parse and remove parts of strings between delimiters

I would like to go through a file and remove certain sequences in between delimiters. For example drw---- 00000000 11111111 0 ./a/ drw---- 00000000 11111111 0 ./b/ d------ 00000000 ...
4
votes
4answers
4k views

Print back-reference in regular expression

I was hoping for a way to make sed replace the entire line with the replacement (rather than just the match) so I could do something like this: sed -e "/$some_complex_regex_with_a_backref/\1/" and ...
1
vote
4answers
218 views

sed -e “s/-.*$//”

What does the -.*$/ in this command mean? Please help me decipher this. echo -n full | sed -e "s/-.*$//" I know what sed does and all that, I just want to know what this -.*$ part is.
0
votes
1answer
534 views

How to insert thousand separator with `sed`?

I want to insert thousand separator into a number sequence with sed and this ugly RE sed -e :a -e 's/\(.*[0-9]\)\(\([0-9]\{3\}\)\(,[0-9]\{3\}\)*\(\.[0-9]*\)\)/\1,\2/;ta' [filename]. Is there a more ...
0
votes
3answers
446 views

Oneliner for multiline regex s/,\n]/]/g?

Can someone provide a simple one-liner to remove certain line breaks? In vim I use %s/,\n]/]/g This should be possible with a very simple one-liner IMHO, but how?
0
votes
1answer
430 views

Sed pattern for multiple lines

I want to remove all create table statements from a mysql script, but the statement runs over multiple lines. Like this: Create table ......NEWLINE... NEWLINE... NEWLINE....; So I tried this ...
0
votes
1answer
181 views

seq with regex, error message for mysql quotes

Is there some tool that auto quotes regex for seq? I can't figure out what I'm doing wrong. I always get this error unterminateds' command` sed -i 's/INSERT INTO `tablename.*`/INSERT INTO ...
0
votes
4answers
246 views

Extract substring using bash

All, I have file names that will be always in the following format "rX_Q_Y_filename.mp3" where X and Y are numbers (0-9). FYI, X and Y in the filename can be 1 or more digits example ...
0
votes
2answers
728 views

Truncate all files in a directory after underscore?

I have a directory with a couple thousand images in it. Most of them have sensible filenames like SD-000.tif SD-001.tif BX-000.tif etc... However probably ~25% of them have names like BX-003_old.tif ...
3
votes
2answers
445 views

sed: Replace an unknown number of patterns on the same line

I'm trying to use sed to search for a certain 'primary' pattern that may exist on several lines, with each primary pattern followed by an --unknown-- number of 'secondary' patterns. The lines ...
0
votes
2answers
275 views

Shell: Trim whitespace in the beginning of files

I have 20k files in here, and at least 1000 of them having white space in the beginning. How can I remove whitespace with sed for example? The problem is, that it may apear some duplicated file ...
4
votes
2answers
2k views

Use sed command to replace , appearing between numbers

I have a CSV file where data are in the following format |001|,|abc,def|,123456,789,|aaa|,|bbb|,444,555,666 I want to replace only those "," that appears between numbers with some other character ...
0
votes
2answers
795 views

Moving characters to the end of line (EOL) with SED

Any time the word “The” appears at the beginning of a line, I want to move it to the end of the line and capitalize the new first word in the line. For example, “The heaven” becomes “Heaven the”. I'm ...
0
votes
8answers
236 views

Unix command to list the portion of the end of a log file from a line containing only hyphens to end of file

I have a long log file where each entry begins with a line containg only hyphens.
0
votes
3answers
248 views

How to use sed or AWK to separate a string (NOT string in files)

How can I separate .sh files into a list? I have tried: ls *.sh | xargs sed 's/\n/ /g' > out.txt The return of ls *.sh is a long string with '\n' in the middle.
10
votes
4answers
5k views

Better way to do “echo $x | sed …” and “echo $x | grep …”

I often find this in scripts (and, I have to admit, write it myself): a=`echo $x | sed "s/foo/bar/"` or if echo $x | grep foo then ... fi Consider "foo" to include some regex stuff. I feel ...
0
votes
1answer
548 views

Replace filename with filepath with sed

I want to replace the string /opt/local/lib/ruby/gems/1.8/gems/cucumber-0.3.99/lib/cucumber.rb with the string /opt/local/lib/ruby/gems/1.8/gems/cucumber-0.3.99/lib/ on the command line, probably ...