2
votes
2answers
46 views

sed error when launching terminal on OS X

I get these error messages when launching bash or zsh in standard Terminal.app or iTerm2 sed: 1: "\#^system_type=# { s#^s ...": extra characters at the end of p command sed: 1: "\#^system_type=# { ...
0
votes
2answers
39 views

Properly escaping forward slash in bash script for usage with sed

I'm trying to determine the size of the files that would be newly copied when syncing two folders by running rsync in dry mode and then summing up the sizes of the files listed in the output of rsync. ...
1
vote
2answers
56 views

Replacing every 10th pipe with new line in unix

Lets say I have fields: name, number, id I have a data file: name1|number1|id1|name2|number2|id2...etc I want to replace every 3rd pipe with a new line or '\n' so I get: name1|number1|id1 ...
1
vote
2answers
34 views

How do I print multiple sections in a text file?

I have a text file looking something like this: *FILESTART line_a line_b line_c *INCLUDE file_A.key file_B.key *INCLUDE file_1.key file_2.key file_3.key *SOMETHING_ELSE line_x line_y line_z *END I ...
1
vote
1answer
61 views

Zsh autocomplete function with sed

I'm struggling to write an ZSH autocomplete function. My goal is to autocomplete ta's and tk's first argument with the projects listed in tmux list-sessions and tmuxinator list. Here's what I have so ...
1
vote
3answers
85 views

Can anyone explain why this pattern matching is not working using sed

Trying to print out specific times of logs based on recommendation from this thread from super user. I am not sure why my patterns are not being matched by sed. I have the sample date and time I am ...
1
vote
1answer
51 views

Matching only numbers that come in numerical order

I have numbers in [.] indicating the page number of an orginal printed document I am transcribing. However, the document also contains other numbers in [.] that do not correspond to page numbers. For ...
0
votes
1answer
46 views

Bash alias with Sed not working

Does anyone know why this alias isn't working? alias tailsed="tailf error.log | sed -e 's/\\n/\n/g' -e 's/\\t/''/g'" I've tried replacing the single quotes with doubles so that it's like: alias ...
0
votes
3answers
39 views

sed rename files moving numbers to end of file

I have a directory that contains several files with the following pattern. 1953-MADAMA BUTTERFLY 1953-MADAMA BUTTERFLY_001 I'm trying to bath rename them to achieve the following: MADAMA ...
2
votes
1answer
70 views

sed: Removing \r\r before \n in a very large file

I have a corrupted disk image file (about 27 GB) in which before all \n characters \r\r was inserted. I want to remove these \r\r before all \n. I tried with awk: awk '{ sub("\r\r$", ""); print }' ...
2
votes
2answers
107 views

sed: How can I replace \r\r\n?

In this question on stackoverflow it is explained how one can replace a newline character using sed. My problem is that I want to replace the character sequence \r\r\n with sed. Can somebody help me ...
1
vote
2answers
188 views

Bash substring last occurance of a character

I am trying to write a script that removes everything after the last occurrence of a character. For example if the string is DATETIME 2014.03.14 12:23:24, I would like to get just DATETIME 2014.03.. ...
1
vote
1answer
89 views

How to replace line in file with pattern with sed?

I'm reading a lot of documentation on sed, and am still stumped on my particular use case. I want to replace this line in a conf file with my own line: Replace this line: #maxmemory <bytes> ...
0
votes
1answer
58 views

Linux/Bash: Comment every line matching a pattern

sed is foreign to me, to say the least. I'd like to traverse a C project tree and comment out every line calling the function LogMsg(). Something that'd achieve the following: foreach: line within ...
0
votes
2answers
77 views

Replace string in string but not when its somewhere between double square bracket

I have a long string from mysql field containing the data of a mediawiki page. I have to replace a string in that mediawiki page but not when the string is in mediawiki link. The mediawiki link is ...
0
votes
3answers
55 views

How do I exclude match and change only specific character with sed

I am trying to use sed to replace '0' with the word 'correct' (I am using echo $? to validate my script and I want to replace the output of echo). The problem is that I have more text in the output ...
0
votes
1answer
69 views

How to delete a line from a file that requires permission such as visudo using sed?

I want to add this command timestamp=20 at the end of visudo file which will increase the sudo time for 20 min. This way I'll be able to use my bash script to install many applications. After I am ...
1
vote
2answers
59 views

Is there a way to print 2 lines (if any) before and after a target or print a placeholder if not?

I'm not native english speaker so I hope to be clear. I know about grep -C 2 "TARGET" inputfile to select 2 rows before and after the row of the TARGET, but I'm not able to use it to manage my ...
1
vote
3answers
85 views

How to select a section from a string in using bash

I have an array containing strings which consist of paths to files in the following format: /path/to/file/14561234545_50303.TXT I'm trying to select the section that is after the "1" but before the ...
2
votes
4answers
545 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
70 views

iterating bash script for cycle in a file

I try to make this very simple bash program that must make the following operations: modify a file java n times: every time I must change a single word in a single line of the file (the line is 11) ...
1
vote
1answer
41 views

AWK does not work correctly in my system [duplicate]

i cant run this code because of an error awk 'BEGIN {x=0;y=0} { match($13,/([0-9]+)/,a); x = x + a[1]; match($12,/([0-9]+)/,b); y = y + b[1]} END {print "rxPackets:" x " txPackets:" y}' yourfile ...
2
votes
3answers
1k views

Extract URL from text with multiple URLs using sed

I have a string with a text and several URLs. How can I extract one specific URL (of a spoecific domain) with sed? For example, I have this: Text foo bar Text foo bar <br /><br /> ...
0
votes
3answers
29 views

Almost-flattening a directory structure

I have a bunch of directories in a structure like this: -Music -Artist1 -Album1 -Album2 -Artist2 -Album1 -Album3 -Artist3 -Album2 -Album4 All the directories will ...
0
votes
2answers
381 views

Replace on Nth Occurrence

I have This Code sed '/Sometexts/ r newtext.txt' old.txt > new.txt This Replaces The String 'Sometexts' with the contents of text file newtext.txt but i want to replace on the 2nd ...
1
vote
1answer
127 views

Write text into first lines of every file

I want my web application to be free software, with a GNU license. I've read that I should add my name and the license in every file. I have a lot of files, so I guess that I could execute a command ...
0
votes
1answer
43 views

Move numbers in a filename to the start

I have several files in a folder, with names in the form: SOMETEXT1 number SOMETEXT2.mp3, or SOMETEXT number.mp3. I want to rename these to number SOMETEXT SOMETEXT2.mp3, or number SOMETEXT.mp3. Using ...
0
votes
0answers
212 views

find and replace in PDF using sed and pdftk

I am doing a mass find and replace using sed and pdftk to find and replace a word in PDF files. When I run the following command, sed -e "s/word1/word2/g" test.pdf I get the following error, sed: ...
1
vote
2answers
68 views

Filtering input with sed (regex)

I'm having an issue with sed not returning what I expect when using a regex pattern to clean up some output from a mysql query. mysql -uroot -p -e 'SELECT `path` FROM db.media_gallery' | sed -n -r ...
1
vote
1answer
248 views

Using sed to enable .htaccess files in Apache config

I am trying to automate the provisioning of an Ubuntu Vagrant box with a Bash script. All is well, but I am having difficulty with configuring Apache to allow overrides from .htaccess files. In my ...
2
votes
1answer
95 views

How to do replace using sed only in one section of file

File looks like this: [section1] a=something [section_name2] a=something [section3] a=something How do I replace a=someother only in section_name2?
1
vote
2answers
254 views

Change names in a column in bash

I have a tab-separated file in Linux that looks like this ~$ head list.tab "x" "1" "FUHGF.jnf.m22-1" "2" "HDFHFEY.gfs.d2-1" "3" "KJFGJF.fr.md2-1" "4" "SDFSDIB.gfd.rtl2-1" "5" "FGJFGOB.hgd.k2-5" "6" ...
2
votes
5answers
576 views

merge groups of lines with sed

I would like to merge each group of lines from file : <tr> <td >441</td> <td >S</td> <td >0,74</td> </tr> ...
1
vote
1answer
86 views

Delete all lines of text in the HTML file in addition to the first?

I have to rewrite a lot of HTML files, example: *--file1.html--* <p>text1</p><br> **<p>text2</p><br> ...<br> <p>text(n)</p>** *--file2.html--* ...
0
votes
1answer
63 views

Sed/Awk line double

I have a list like this. Bob Jim Steve Is there a way in bash to turn that into a list like this? <a href="http://example.com/Bob"> Bob <a href="http://example.com/Jim"> Jim <a ...
1
vote
1answer
128 views

Grep to find files that contain ^M When ^m dos2unix and sed or “grep -r $'\r' *” does not work

I use Cygwin and made a txt file using a Perl script. There is a ^M (Windows cariage return) added, and I have no idea how. How do I find ^M when normal ways (^m dos2unix and sed or "grep -r $'\r' ...
0
votes
3answers
112 views

Possible to use more than one core with sed and bash?

I am looking to use more than one core when replacing values with sed in bash, is this possible?
3
votes
3answers
283 views

Need to sed awk or grep output to extract strings

I have output which looks like this: "vancouver/news/vancouver-voices": { "status": 0, "time": 0, "timestamp": 1371298701 }, "vancouver/news/vancouvers-march-second-annual-success": { ...
1
vote
3answers
342 views

sed quotes and backslashes on cygwin

I am trying to extract a substring from a string with sed on cygwin. #!/bin/bash var1="foo\ bar" var2="baz" var3="$var1 $var2" # extract "foo\ bar" from "foo\ bar baz" var4=`echo $var3 | sed ...
0
votes
0answers
52 views

How do I script a config file change

I'm trying to create a script to make the vi color change described here http://www.kavoir.com/2009/05/how-to-change-vim-syntax-highlighting-colors.html Trying to do it with sed but it's not working ...
0
votes
1answer
189 views

sed command working in command line but not in script [closed]

I have a script with the follow code: find . -name "*.html" -print0 | while IFS= read -r -d '' n; do sed -i -r 's/<font ...
0
votes
2answers
745 views

Replacing a dot with an underscore in a file using sed

I was trying to edit the output of a file using sed. The contents of file are cat /tmp/Group_RM t.p@k.p t.m@k.k I was trying to get the output as: cat /tmp/Group_RM t_p@k_p t_m@k_k I tried the ...
3
votes
1answer
3k views

Using grep to remove lines from a file which contain a string from another file

I have a file containing words (one per line) such as Dog Fish Cat Shoes I have a secondary file in CSV format such as 1,shoes,red 2,apple,black 3,fog,blue I would like to use grep with ...
0
votes
2answers
266 views

Deleting line from file using SED in MultiUser Case

I have a scenario where multiple users are connected to a server using SSH. I have a file which is read and written by all the users. The file contains numbers like this - 14554 14887 23451 15135 ...
0
votes
2answers
85 views

Deleting all word occurences with sed preserving linefeed

I'm trying to delete a word's all occurences in a text file with sed. I have this file f1: alma a fa alatt nyari piros alma and I'd like to delete all occurences of "alma". I use the ...
-1
votes
2answers
118 views

Replace all numbers following a specific string with another number using sed or awk

I have tried several things but got no luck. I have an input file that has a lot of fields like this one weight=0.123456 mixed with other fields. I want to multiply all such weights by a factor, say ...
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
3answers
3k views

Bash: Find and replace text strings

I figured this would be easy, but I'm overlooking something simple: I have a text file called test. It contains, for example, the string Alfred Hitchcock. I want to replace this with Alfred\ ...
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 ...
2
votes
3answers
1k views

How can cat/print a file except the last 2 lines?

How can get a file, except the last (for instance) 2 lines, with standard or GNU shell tools? (bash, tail, cat and so on.)