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

learn more… | top users | synonyms

3
votes
0answers
41 views

Transpose a file, and replace missing values by

Please guide with the following data formatting. I have Readings for Names, from Machines and sometimes these readings are replicated. Where a reading was not found, it is left as blank. Name ...
0
votes
1answer
29 views

Why does the input to xargs is 1 string but without is strings in separate line?

I am trying to pipe file to rm via xargs. I understand that what I am tryng to do could be done by git clean but I am practicing the cli. I tried this: for files in $(git status --porcelain| sed ...
0
votes
3answers
36 views

Separating names separated by “| character” to individual pairs

I want to separate the names in the same line into separate individual pairs. TMPRSS2|pp9284 AADAT Sample1 ERG TMPRSS2|pp9284 Sample2 TMPRSS2|pp9284 ETV1 Sample3 PDE4A ...
0
votes
4answers
30 views

Awk/sed command to cut on multiple delimiters [on hold]

I have input file name as: Sample_0000860156-001-out_20150224150524.xml.gz I want only 0000860156-001 from the file_name to append to my target file name.
0
votes
1answer
33 views

problem with sed inside sed

i am trying to parse a string inside a sed command but i am getting errors. if some1 can help me... it would be nice. i dunno what else to try sed -e "/pd begin $(echo 3:1I:1:1|sed 0,/:/{s/:/' ...
-5
votes
1answer
24 views

Remove characters from string with sed [on hold]

I have this header: >tr|G3Q381|G3Q381_GASAC Uncharacterized protein OS=Gasterosteus aculeatus PE=4 SV=1 and I was thankfully helped on here to get it to: >G3Q381_GASAC but now I need to ...
0
votes
0answers
28 views

SED and regex expressions… addr1 and addr2

How can I use sed to match 'addr1' and reuse it again in 'addr2' field? #Ex.: echo "12a34" | sed 's/a/#bcd/g' # 12abcd34 #\# = match addr1
7
votes
4answers
180 views

Matching and pasting to line

So I have 2 very big text files, consisting of lines like so: First: Robert:Dillain:Other:Other:Other Julian:Brude:Other:Other:Other Megan:Flikk:Other:Other:Other Samantha:Minot:Other:Other:Other ...
2
votes
3answers
41 views

how to use awk/cut to get column data which has space

I have data in below format: 16 SQL*Plus vilconv1 dox-conv2 16 TOAD background query session Disha WORKGROUP\AD now I want to ...
0
votes
1answer
21 views

How to change a single line in multiple files [duplicate]

I have ~750 .php files in the same directory that contain the line include("path/to/file.php"); I would like to change this line in every file to require_once("path/to/file.php"); What would be ...
3
votes
3answers
46 views

sed command and formatting one line help

I need help turning these headers: '>>tr|G1PEZ0|G1PEZ0_MYOLU Uncharacterized protein (Fragment) OS=Myotis lucifugus GN=SNCG PE=4 SV=1 into just this: '>G1PEZ0_MYOLU I've given up. I ...
1
vote
1answer
42 views

Single record of a file getting splitted over multiple lines

We are using flat text files to store in teradata table after transformations from Informatica. The file contains 14 fields (~ separated). But as the records are getting scattered over multiple lines ...
0
votes
1answer
55 views

Space removal after a pattern in SED

I have a file instrument.xml bash-4.1$ more instrument.xml <instr instr_id="CPT-2380950-011-001-826" valor_ch="" instr_type="CurrentAccount" instr_name="CPT-2380950-011-001-826" qn_type="1" ...
2
votes
1answer
34 views

Replacing by tab character in Sed in Osx

I am working in Mac OS X,I have tried several commands in sed to replace by a tab character followed by a file name. for f in *.txt; do sed -i '' -e "s/$/\t$f/g" $f; done for f in *.txt; do sed -i ...
1
vote
4answers
63 views

Replacing pattern with variable

I have 3 lines of numbers stored in a variable $new and I need to use this to replace 3 lines from a file which I have used grep and stored in another variable $old. I'm trying sed "s/$old/$new/g" ...
-1
votes
1answer
82 views

replace text in a file

are there any usefull command to replace all text that contain number and remove those number . Ex: myimages-202x250.jpg width="202" heignt="250" replace to myimages.jpg width="217" height="317" ...
1
vote
3answers
29 views

Print more than one line from a text file

I am using the following code to print the second line from a file: sed '2q;d' file what can I add to this code so I can print two or more lines at once?
0
votes
3answers
263 views

How to delete html tags from a file using sed ?

I have a file that is mixed with both normal text I need and html-tags. I know that with REGEX it is possible to recognize html tags and with sed one can swap those for an empty string, but I do not ...
4
votes
3answers
77 views

How can I find and replace only if a match forms a whole word?

My script is: n="y" while [ "{n}" = "y" ] if [ $n == "n" ]; then break; fi echo "n is $n" do read -p "Enter the word to find = " word read -p "Enter word to replace = " replace ...
1
vote
2answers
99 views

extract blocks of text from xml file

I have a file with these contents: <People> <Person> <Name>Joe Blogs</Name> <Address>55 Oxford St</Address> ...lots of other properties ...
0
votes
2answers
27 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ő ...
3
votes
2answers
42 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
72 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
43 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
31 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
48 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
27 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
190 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
34 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 ...
0
votes
0answers
24 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
56 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
39 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
92 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
60 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
66 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
101 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
97 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
39 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
107 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
60 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
23 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
27 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
71 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
50 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
41 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
2answers
121 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
61 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
41 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 ...
4
votes
2answers
201 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 ...