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

learn more… | top users | synonyms

0
votes
1answer
21 views

Parse header in a file and based on the header replace a value in the file

I have a problem I need help with. I'm not very experienced with awk, but it seems to be a good tool for this job. I have the following file Field1|Field2|Field3|Field4|Field5 a|b|c|d|e 1|2|3|4|5 ...
-1
votes
0answers
26 views

problem in AWK with Shell scripting [on hold]

Aim : I have 5 .CSV files namely 1. A.CSV 2. B.CSV 3. C.CSV 4. D.CSV 5. E.CSV I just want to copy the header column names from each file and place to another file named Header.csv . Code : ...
5
votes
4answers
157 views

Want to substitute only first occurence with sed

Original file claudio antonio claudio michele I want to change only the first occurrence of "claudio" with "claudia" so the file result claudia antonio claudio michele I have tried sed -e ...
1
vote
2answers
40 views

Creating multiple input files by using sed in a for loop

I am a newbie and wasted a lot of time on this so any help is greatly appreciated. Suppose I have a simple Mathematica script file named "a.m" which contains the parameter 'a' with no assigned value: ...
0
votes
3answers
36 views

I want to condense a list of ranges (from-to)

I have data involving codes assigned to ranges in the form of From To Code 0 5 A 5 10 A 10 15 A 15 20 B 20 25 B 25 30 A 30 35 A 35 ...
0
votes
1answer
28 views

why isn't this expression finding whitespace after the date?

I'm using sed to find any expression that matches a date in the format 00/00/0000 with any amount of whitespace after and simply replace it with the letter h. I made the expression: sed -E ...
1
vote
1answer
29 views

remove lines where a field's value is less than or equal to 3 - sed or awk?

I need to remove every line that has a value of 2 or less in the 8th field (column). My data looks like this: 12-31 Airport 189 379 41 49.70946503 -124.91377258 2 2880 30.8 01-01 ...
1
vote
1answer
20 views

How to replace string of the file, which is present in tar file through UNIX

I have a tar archive xyz.tar containing lots of .sh files like: 123.sh 456.sh 789.sh Every .sh file has some string content, e.g. 123.sh contains welcome to Hollywood, 456.sh contains I love ...
3
votes
5answers
161 views

Pick the latest file based upon the sequence number given in the file name

I have a requirement, I have few files in a directory, I need to pick the oldest one for processing. For Exp: I have below files in /tmp directory: Sample_0000237826-001_xyz.dat ...
10
votes
3answers
509 views

How do I replace the last occurrence of a character in a string using sed?

How do I replace only the last occurrence of "-" in a string with a space using sed? For example: echo $MASTER_DISK_RELEASE swp-RedHat-Linux-OS-5.5.0.0-03 but I want to get the following output ( ...
0
votes
1answer
22 views

Error with sed on MAC OS X invalid command u

Im french sorry in advance for my bad english... So i have an error on MAC OS X when im using sed sed -i '' '/user_pref("mail.identity.id1.reply_on_top", 1);/ a\ ...
6
votes
3answers
193 views

Sed alternative for search and replace on very long lines

I have files that were generated by a program that did not put newlines at the end of records. I want to put newlines between the records, and I can do so with a simple sed script: sed -e ...
1
vote
0answers
32 views

delete non important characters from command output

the version command in my Linux machines display the following output version Red.Hat.OS. release..........5.5 APP.Release.............4.2.0.0-02 how to remove the middle "." dot character ...
-1
votes
0answers
18 views

Sed to replace two patterns [on hold]

Old format: CAST ('${HIGH_DATE}' AS DATE FORMAT 'YYYY-MM-DD') To be replaced with new format: CAST(CAST('${DEFAULT_HIGH_DATE}' AS DATE FORMAT 'MM-DD-YYYY') as DATE FORMAT 'YYYY-MM-DD'
1
vote
0answers
60 views

Sed regex printing into a file.txt

I'm connected to a MQTT stream, and I filter out the data by entering : mosquitto_sub -d -t +/# 2>&1 | sed -n "/PUBLISH/{s|.*\('.*',\).*|\1$(date),|;N;s/\n//;p}" into the Ubuntu terminal. ...
3
votes
0answers
60 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
37 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
40 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
3answers
38 views

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

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
34 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
25 views

Remove characters from string with sed [closed]

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
30 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
206 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
44 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
25 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
46 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
57 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
35 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
83 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
270 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
80 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
105 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 ...
1
vote
2answers
41 views
+150

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
43 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
45 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
35 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
1answer
38 views
+100

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
58 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
44 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
102 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
62 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 ...