sed is a command-line stream editor for filtering and transforming text.

learn more… | top users | synonyms

1
vote
4answers
126 views

How to insert a variable in a variable in a random place?

Q: How can I insert variable $b to a truly random place in variable $a? Example INPUT variable content: $ echo $a árvíztűrő tükörfúrógép $ echo $b ZZ OUTPUT $ ./somemagicscript.sh árvíztűrő ...
4
votes
2answers
83 views

How to “grep” for line length in a given range?

I need to get only the lines from a textfile (a wordlist, separated with newline) that has a length range of minimum or equal than 3 characters, but not longer or equal then 10. Example: INPUT: ...
0
votes
2answers
82 views

what are considered old and powerfull commands? [closed]

I came across the terms awk and sed, awk goes once through all lines and performs a task whenever a line meets a certain condition, sed can manipulate a stream of input before it goes further to the ...
1
vote
3answers
53 views

How to replace string with abc\\efg[255 with abc\\efg[23 using sed

I have a file and it has lines starting with abc. How can I replace the string abc\\efg[255 with abc\\efg[28 using sed?
0
votes
1answer
50 views

Regex for matchng anything between parenthesis

I have the following regex so far: printf "this is (test.com)\n" | grep -Po '(?<=\().*(?=\))' The above regex will print the desired output, which is test.com As far as I am adding new ...
2
votes
1answer
55 views

how can I add an extra character after a word search [closed]

I have the following field names demelog voyapro naisjdf naismc decoide decoccm travide travccm equiccm mariccm Below is a sample of my file. There are more columns before the first fck=83... ...
1
vote
2answers
49 views

Using `sed` in Android without `g` modifier?

I have Stericson busy box installed in my rooted Nexus 10. I wanted to replace the first instance of </verse-sub-section> with </section> in the file here: <section>Psalm ...
4
votes
3answers
230 views

Can tr commands be chained to avoid multiple tr processes in a pipeline?

I have a bunch of txt files, I'd like to output them lower-cased, only alphabetic and one word-per line, I can do it with several tr commands in a pipeline like this: tr -d '[:punct:]' ...
2
votes
2answers
41 views

how to print the closest column when looking for a specific strings

I have a file with around 12 000 lines. ...
0
votes
0answers
13 views

how to keep the spaces when inserting line to parameter [duplicate]

When I want to see for example the line number 2 , from the CSV file I get the following line example1 LINE_NUM=2 # sed -n "${LINE_NUM}p" file.csv cwdfwefwe,"aaaaa ","\dsw\dawd\aw ...
2
votes
4answers
101 views

How to highlight given string in given place?

How can we modify this: <a href="http://foo.bar1">asfdlksafbar1qsasadf</a><br> <a href="http://foo.bar2">svasfbar2saldkfj</a><br> <a ...
1
vote
3answers
101 views

How do I replace a string with dollar sign in sed?

I want to replace this string: export TODO_FILE="$TODO_DIR/todo.txt with: export TODO_FILE="$TODO_DIR/writing.txt" in the file ~/.todo/config. I've run it with: sed -i 's/export ...
1
vote
1answer
62 views

sed regex not working for hidden characters

I have a list that has for some reason got some non alphanumeric characters appended to the end. I would have thought it would be a simple case of running : sed 's/[^A-Za-z0-9]$//' To replace ...
0
votes
3answers
638 views

create XML file using bash script

I want create simple xml file using bash script ( not with dom ) but when I set value in the line then echo print the $lorem word and not the val lorem=LOL echo '<root><foo ...
0
votes
1answer
100 views

Reading a string till a key word and replacing from there with another string

I am new to UNIX and am practising shell scripting. I have an application where I need string searching and replacement. There are some lines in a file 1 and file 2. I have a search key word. If the ...
0
votes
3answers
129 views

Using sed to remove digit separation commas enclosed in quotes and quotes itself from CSV? [duplicate]

How can I can use sed to remove from before-last column the group digit char comma and quotes itself? Please note that in the sample below the target column is not contained in double quotes. ...
1
vote
1answer
191 views

grep (/sed/awk) month range

I've looked around for solutions to this, but it's sort of difficult to search for the solution to such a specific problem (lot of words to put in Google). So, I have a file with data that looks like ...
2
votes
2answers
132 views

How do I have sed only perform actions on the first match?

I have a bash script that extracts headers from the MIME Source of an email. The idea is that I only want to capture the headers of the message nothing else. It's not quite working right though. I ...
0
votes
0answers
66 views

Bash - Convert escape character colored text to BBCode

I want to convert a terminal escape-character colored text file to BBCode colored text. For this i've created an Android logfile with logcat -Cd > /sdcard/logcat.txt. The -C switch adds the color ...
1
vote
3answers
283 views

sed won't expand my BASH variable in script

I have this script, which will prompt for the relative or absolute path to the file and then swap whitespaces ' ' with '\ ' which works in Linux console. Substitution is done using the first sed ...
0
votes
5answers
135 views

sed to replace with backspace

I have trail.txt, which contains spice netlist. Now I want to replace all expanded parameters to one line only i.e. remove + and append that line to previous line. trail.txt data + net06706 ...
0
votes
1answer
25 views

Coordinates X237595Y81600 to X2375Y8160

I have create a gerber file and it has lines inside which look like this: X90095Y15350 X100095Y15350 X110095Y15350 X120095Y15350 X120095Y25350 X110095Y25350 X100095Y25350 X90095Y25350 X80095Y25350 ...
0
votes
1answer
64 views

Sed with angle brackets

This works sed 's/[[:space:]]*<default>false/XXX/' Why does prepending a > make it fail sed 's/>[[:space:]]*<default>false/XXX/' escaping the > does not help either. In ...
0
votes
2answers
116 views

sed to replace a word from a file with the contents of another file? [duplicate]

I have two files file1 & file2. Contents of file1: Text1 Text2 Text3 Contents of file2: Sample1 Sample2 Sample3 I would like to replace the word Text1 from file1 with the contents of ...
1
vote
1answer
97 views

How to add the content of a text file to the middle of another text file

I tried to use sed, but I realized that it doesn't allow to charge a complete file. I am looking for a quick and neat way to: a.txt a b c b.txt d e f And obtain c.txt a d e f b c
1
vote
2answers
46 views

Generate Sequence number for each line at the end .. modified t he post can someone help&suggest on this

I am new to linux I have got this query sed '/./=' abc.txt| sed '/./N; s/\n/, /' >> as.dat source file has 3 rows like below a b c When use the following command it gives me result like ...
4
votes
1answer
207 views

sed command inside sed

Is it possible to run sed command inside sed, something like this: sed -i.bak -e '${sed -n 1,1p file.txt},$d' output.file I want first line of file.txt which is number to be input parameter for ...
0
votes
1answer
117 views

regex find replace strings starting or beginning with backslash

I have a compilation album in my music library that has song titles in the form of ARTIST/ TITLE, which is making it really difficult to cp or mv these files because of the slash. So I'd like to ...
3
votes
3answers
84 views

Append and write out variable-named file from list of variables

I would like to create multiple 'wget' shell scripts to download a batch of considerably large (~3GB) files using our HPC cluster. The names of the files are stored in filenames.txt, like so: $cat ...
5
votes
2answers
637 views

sed: read whole file into pattern space without failing on single-line input

Reading a whole file into pattern space is useful for substituting newlines, &c. and there are many instances advising the following: sed ':a;N;$!ba; [commands...]' However, it fails if the ...
3
votes
2answers
190 views

Capture in shell variables the arguments after a command (between brackets)

Suppose I have a file that contains, among many other things, \command{arg1,arg2,arg3} (arguments been paths, expressed with /, ., characters and numbers) But that a user can as well call it ...
3
votes
2answers
226 views

Find the line number which contains the pattern with custom delimiter

As in example I'm trying to get line numbers which contains the pattern. My pattern contains slashes so I wanted to add custom delimiter. This simple one works: sed -n '/file/=' temp.txt Using ...
1
vote
1answer
62 views

split line based on space and delete the second part

I have a big file >fid|29290408|locus|VBIEntCas2262_0001| Phosphoglycolate phosphatase (EC 3.1.3.18) [Enterococcus casseliflavus EC20] ...
1
vote
2answers
88 views

Copy the first 2 lines from a file and then remove the lines

I need to process a file using a shell script. The file arrives with the data as well as some embedded information releavant to how it is processed. The file is in the following format; ...
3
votes
5answers
233 views

How to replace only the third occurrence of the file in unix using only sed command?

How to replace the third occurrence of the string in the file using sed command. Example: Change only the third occurrence of is to us in the file. My input file contains: hai this is linux. hai ...
1
vote
2answers
55 views

Why does regex with \\$\{ work with egrep, but not with sed?

Given a text like this ./RFF_09 -f${FILE} -c${COND} inside a file, this egrep command will correctly match: egrep './RFF(.*) (.*)-c\\$\{COND\}' file but this sed command will not sed -n ...
3
votes
7answers
1k views

can we print the last word of each line in linux using sed command?

suppose , if there is a file consisting of following lines , if they are 12345 567 7878 66 er3 t45t y6y46y 4y6 y656y y5y 46y6 65y7 y66uyuy yy46y6y The output has to look like: 66 ...
2
votes
3answers
106 views

Adding text to beginning of text file

I am trying to add a line of text to the beginning of a text file (Actually not text, but just two backslashes). I am trying the following, which I found in this answer: Add lines to the beginning and ...
0
votes
1answer
34 views

Insert space at specified position in a file

I have this sample file: 234234|111||J1X0H8|SERP||R|D|666|M 234235|222||J1X0N5|SERP||C||555|M For each line, I need to insert a space after the 3rd character of the 4th column, like so: ...
0
votes
2answers
339 views

How to convert Log file to CSV using bash

Is it possible to turn this log entry into a properly formatted csv file using sed/awk? I've tried multiple ways to do this using sed/awk. Alas I couldn't do it. Before I do it in perl. is this ...
1
vote
3answers
83 views

Removing mulitple lines

I am trying to write up a command line interfaces that will removes a particular section / lines of codes within a list of json files. By the way, the json file are located within the sub-folders of ...
2
votes
3answers
261 views

Replace multiline string in files

I have a number of files I want to update by replacing one multi-line string with another multi-line string. Something along the lines of: * Some text, * something else * another thing And I want ...
2
votes
4answers
68 views

Removing an empty line and the line above it

I have a large .fna file containing millions of DNA sequences. Due to some write errors after truncating my primers, I'm left with some sequence headers with no sequence following it. An example is ...
3
votes
3answers
419 views

sed fails to remove newline character

I've been using sed for quite some time but here is a quirk I came around with, which I am not able to resolve. Let me explain my problem with the actual case. Scene#1 printf "ls" | xclip ...
4
votes
2answers
215 views

sed “e” and “g” flags not working together

Given this: echo AAA | sed -r 's/A/echo B/ge' I get this: Becho Becho B I would have thought I would get "BBB". This is with GNU sed version 4.2.1. What is going on, and how can I use the ...
4
votes
3answers
66 views

How to select first occurrence between two patterns including them

How can I select first occurrence between two patterns including them. Preferably using sed or awk. I have: text something P1 something content1 content2 something P2 something text something P1 ...
0
votes
0answers
14 views

Escape ampersand in bash variable used as a sed argument [duplicate]

I have a template Hello NAME welcome and want to replace NAME with data like "Judy&Mary". Why does this not work? TEMPLATE="Hello NAME welcome" DATA="Judy&Mary" echo $TEMPLATE | sed -e ...
0
votes
3answers
62 views

how to replace a character within in a multiple double quoted words within a line using sed?

I have text file including text format like this. 012345,"[ThinkPadT2/3Gband,Mac]",Lenovo,"iPhone3G,A1241" How do i replace comma inside words only within double quote by pipe(|) operator using ...
1
vote
1answer
50 views

How can I use regex to extract the text following two conditions into a variable?

I'd like to extract a setting for a given host in the ssh_config file and put it into a variable. Host mysite HostName 123.1.1.1 User myuser Port 13245 GSSAPIAuthentication no ...
1
vote
2answers
94 views

Formatting ifconfig using sed/awk

I'm using ifconfig on OpenSUSE. When I run ifconfig eth0 I get eth0 Link encap:Ethernet HWaddr CE:FD:75:DF:A5:6D inet addr:172.16.4.177 Bcast:172.16.5.255 Mask:255.255.254.0 inet6 ...