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

learn more… | top users | synonyms

3
votes
4answers
251 views

Using sed for brackets

I would like to find out, if, in my file, there is a right number of brackets. I can make my file look like (((()))()(())) ((()))() How can I use sed to compute those brackets and print yes or no ...
1
vote
1answer
125 views

Output different lines when comparing two files

I have two text files with the same number of newline terminated strings. The lines in the two files correspond to each other. The lines in each file individually might be repeated. I would like to ...
1
vote
4answers
90 views

How to remove line based on Delimeter in perl / Shell?

Can anyone help to remove the line in file based on delimeter(Comma), Incase if line contain less number of columns or Bad records , Need to delete those. Input File: a,b,c,d a,b,d,f c,d a,v,b,h ...
3
votes
4answers
257 views

How do I extract the first integer from text string in a column of a tab-delimited file?

I work in Medical Genetics and often have delimited text files where in one column (ex. column 5) there is a text string with a "mutation" in our jargon: c.2458C>T or c.45_46delAA or ...
0
votes
1answer
48 views

How to find & replace pattern WITHIN specific pattern using sed

IT seems that 'sed' and I will never be friends... How can I find and replace a pattern within a range (within another pattern)? In words: Find: AllowOverride None within the following range and ...
1
vote
4answers
205 views

How to recognize which ASCII character in hex is this?

We have a textfile that we want to clear from "bad" characters. If we open it with vim (with ":set number"): 57000044 zo¥<9a>¥ge¥o¥graph¥i¥cal¥ly 39999999 pariá¹<83>Å<9b>a The ...
0
votes
0answers
14 views

How to change the string /vol/oracdump/ with /vol/nfs_ssdb/vmcoredump using sed ? Please help me [duplicate]

How to change the string /vol/oracdump/ with /vol/nfs_ssdb/vmcoredump using sed ? Highly appreciated if I get your response.
1
vote
2answers
89 views

sed - doesn't append new line EOF and replaces letter not defined

I am experiencing a strange behavior using a sed command (got to be sed, no awk in this case) and got two questions for you, hoping someone got the skills to explain me what I am doing wrong. I want ...
5
votes
5answers
452 views

How to replace a word with new line

I have a text file with following data and each row ends with |END|. T|somthing|something|END|T|something2|something2|END| I am tryig to replace |END| with \n new line with sed. sed ...
0
votes
1answer
58 views

Error while passing variables for keyword match using sed

I am a beginner in scripting. I am writing a bash script for text processing where this command is giving me error: sed -e "/\<$7\>/ /\<$5\>/$6/" < "$2/$1" > "file.tmp" This is ...
0
votes
2answers
75 views

Find and replace values with counters [closed]

Sorry my earlier question was bit confusing... I have a file that has values like: location 100 SlotNumber ..some lines inbetween location 150 SlotNumber ..some lines inbetween location 160 ...
1
vote
1answer
42 views

Trouble with Sed Syntax

I'm modifying raw PCL/PS files (mixed) and for some reason I can't get my Sed syntax right for the true beginning that I want it to grab. Here's a sample output from the strings command: *c50B *c0P ...
1
vote
2answers
54 views

SED replace after ignoring

There are many lines in a text file and I would like to change the value true to false using a one line script. bash-3.2$ grep online test.txt # online = false --> ONE SHOT import (delete all ...
0
votes
2answers
38 views

Select lines and format

Is there a way to format the following output so that only lines 1 and the respective lines that state the "rule" name print out? Depending on the configuation, the "rule" line could vary. It could be ...
1
vote
1answer
60 views

Pattern matching and removal of that pattern using sed

I have 2 files with the following names: File 1: RvA_X-IRB-bil-CA101-0+010000-20150327212332-055582-P File 2: RvA_X-IRB-bil-CA101-1+020000-20150327212332-055582-P I am using this command to match ...
0
votes
1answer
81 views

Modify part of line if keyword is found using sed? [duplicate]

I want to modify a line if a specific keyword is found in a line. CS_CODE, SM_NUM, PORT_NUM, DEV_PORT_NUM, DIRNUM, MAIN_DIRNUM, BILL_NO, ADR_NAME In above line, if 'PORT_NUM' is present then ...
4
votes
3answers
261 views

Get last part of string after hyphen

Is there a simple command line to extract the last part of a string separated by hyphens? E.g., I want to extract 123 from foo-bar-123.
1
vote
5answers
72 views

keep out line break

I have some files with this structure: 2015-03-25 17:08:17 sysUpTimeInstance 93474;^M 1.ValueforState=2500 I want to replace the line break, and leave the third line with the second line, I mean, ...
1
vote
2answers
60 views

Parsing C Style Multiline Comment

I want to filter non-commented javascript with sed and output the line number Here is the example: /*! * jQuery UI 1.8.17 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Dual ...
1
vote
2answers
69 views

How to list only the last line of each directory?

I learned thanks to you, how to display only the last line of a listing,e.g. ls -ltr | sed '$!d' Now I thought, how to combine it with the find command, in order to repeat this onto each directory ...
0
votes
3answers
49 views

How to display only the last line of a listing ?

Supposed I make a listing and sort the files by its temporal attribute: ls -ltr -rwxrwxrwx 1 bla bla 4096 Feb 01 20:10 foo1 -rwxrwxrwx 1 bla bla 4096 Feb 01 20:12 foo2 . . . -rwxrwxrwx 1 bla bla ...
0
votes
0answers
28 views

Would this command delete only the lines containing specific words within a delimited area? [duplicate]

Please see my previous question here. No one seems to be following up on it, so I have tried to have a go myself: sed '1 { /^---/ { :a N; /\n---/! ba; /^Title: \|^Place: /d} }' filename Would this ...
1
vote
1answer
56 views

Write text on last line of document [duplicate]

If I have this document aaa bbb ccc And I want to add " ddd" on the last line. My document should look like this: aaa bbb ccc ddd How can I do this? If I prefer awk or sed but ...
1
vote
2answers
141 views

Remove paragraph from file

I have a file (file.php) like this: ... Match user foo ChrootDirectory /NAS/foo.info/ ForceCommand internal-sftp AllowTcpForwarding no GatewayPorts no ...
0
votes
1answer
43 views

Sed a plist file gives a iilegal byte sequence

With a Unix Mac 10.9.5, French CA version I've read a lot of tips but if the error is gone, the plist is corrupted. the locale command gives: LANG="fr_CA" LC_COLLATE="fr_CA" LC_CTYPE="fr_CA.UTF-8" ...
3
votes
1answer
104 views

sed match pattern and act on x lines after

I'm trying to find a way to comment out a block (multiple lines) in a configuration file. I'd like to match the first line but also act on each line after that. sed '/\/Some\/Foo\/Bar\/String/' ...
3
votes
1answer
56 views

How to avoid sed -i to destroy symlink?

Why does sed -i executed on symlink destroys that link and replaces it with destination file? How to avoid this? eg. $ ls -l pet* -rw-rw-r-- 1 madneon madneon 4 mar 23 16:46 pet lrwxrwxrwx 1 madneon ...
1
vote
2answers
91 views

Sed move line from n° 40 to 39 position [duplicate]

I have a text file,of 100 lines,i need to move line 40 to line 39(refer to position) How to do this with sed? I tried sed '40 m 39' file and sed '40,39m' file but give me error. Thanks
0
votes
2answers
119 views

How to delete specific lines within a certain area?

I want to delete some specific lines in the YAML front matter: --- Author: aaaa Title: bbbb Time: cccc Place: dddd ... Lets say I wanted to delete only the lines in the front matter that contained ...
1
vote
4answers
255 views

SED command to format text file

I need to create a SED command to modify an input file with some conditions explained below. I have an input file something like below. List item Rad# ; ID_KEY ; UNIT_ID 1 ; 30000000004 ; 8417920 ...
0
votes
2answers
293 views

sed command to replace a string from one file with entire contents of another file [duplicate]

I want to write a sed (or awk) command to replace a string from one file with the entire contents of another file. Note that second file from which I want to get the content has more than one line. I ...
3
votes
1answer
64 views

sed - perform multiple substitutions on a line found by pattern search?

I have a file which contains a like like this: name=MOD0 and a lot of extra lines which I'm not interested in. I need to transform this line into this: [MOD0] and drop all other lines from the ...
0
votes
2answers
71 views

Replace a range of text with special characters using sed

I am trying to replace a range of text with sed containing special characters. I have the following output: "Users" "/Users/Users" SERVER1 "Roaming Profiles" "/Roaming Profiles/Roaming Profiles" ...
4
votes
1answer
147 views

how to change the replacement of word in the specific line using sed command?

I have to change a word in the 4th line so I used this command: sed -i '4 s/previous_word/new_word/' filename and it worked perfectly. But if I save the line number in a variable and try the same ...
2
votes
2answers
79 views

Using the sed command in Unix

how do you take one word from a file and change it to an absolute path? Basically I need to take one word from a unix file and change it to a absolute directory path in that file. The file name is ...
2
votes
5answers
203 views

sed, find and place after and before

I have massive text with different dates and hours so i cannot use it as pattern and i was thinking if it's possible to search for 1st , and AFTER it print " & search for 2nd , and BEFORE it print ...
2
votes
3answers
262 views

how to delete line from the XML file

how to delete only the line from xml file ( with sed/awk or perl one liner line ) that start with: <units> and ended with </Networks> as the follwoing <units><unit ip= ...
2
votes
2answers
350 views

Strip #xxx comments except when they occur inside quotes in sed

How to solve the following problem? Input hai this is "#test" #this is comment Question: How to remove only the comment in shell script. Expected output: hai this is "#test"
2
votes
2answers
106 views

SED on Mac OS X

I'm using a MacBook Pro and I want to find and replace a given word with another with sed command, but it makes no changes. What is the problem? sed 's/\<cat\>/dog/g' tt.txt
2
votes
1answer
98 views

Expanding paths in Bash variables into sed expressions

I would like to ask what's wrong with this line? sed -i "/$PWD/a\ Hello World" historia.txt when I had it in this '' except for "" it was working, of course without expanded variable.
1
vote
3answers
108 views

Swap line containing pattern with next line

I currently have the following code which nicely outputs some information about the wireless networks around me: sudo iw wlan0 scan | sed -nr '/SSID: |signal: |primary channel: /p' | sed ...
1
vote
1answer
91 views

Problem with sed substition in multi-word regex

Take this simple example: echo "20150310 21:12:01.846338::: <?xml version="1.0"?><Haystack><Event " \ | sed 's/^\(.\{24\}\)::: \(<?xml.*><Haystack\|Foo\)>\(.*\)/\2 ...
0
votes
1answer
63 views

effect of [0-9]* in a regular expression

What is the function of [0-9]* in the following statement, which will write all lines that start with an even number, followed by a space, to the file even: sed -n 's/^[0-9]*[02468] /&/w even' ...
4
votes
2answers
175 views

Replace string in a file with another where both are saved in variables

I want to replace a string found in a file with another string, but both have a special character (in this example it is a . char) e.g 1.0 and 2.0. So this is the command currently used: sed -i ...
1
vote
1answer
44 views

Replace a string in a text file using a shell script not working properly

I have a text file containing this: 0 0 -1 0 1 0 0 0 0 -1 0 0 1.5 0.0 1.0 1 and I want to replace the 1.0 to 2.0 so that it becomes: 0 0 -1 0 1 0 0 0 0 -1 0 0 1.5 0.0 2.0 1 so I use this ...
0
votes
1answer
28 views

Multi line substitution duplicating across lines in OSX

I'm a little rusty in my sed and haven't used it much since moving to a Mac but I am aware there seems to be a difference with what sed is used on a Mac per Ubuntu after a few searches. What I am ...
2
votes
5answers
190 views

How to reverse the lines between a pattern into another file

I have the following in the input file #Start para 0 hello dq 1 world dq 2 welcomes dq 3 you dq #Start para 0 how tq 1 are tq 2 you tq #Start para 0 say dq 1 hello dq 2 to dq 3 the dq 4 world dq I ...
1
vote
2answers
45 views

How do I update the dates (by 30 days) in the files going to that specific location in unix?

How do I update the dates (by 30 days) in the files going to that specific location in unix? Can awk or sed help ? File format is as below - Thomson: xyz Format: 1 Character_set: ASCII8 File_type: ...
1
vote
3answers
211 views

A sort of reversed cat [closed]

I've two documents that are the result of SQL Queries. For exemple i've my Doc1.lst that is : John1 0 Julien 10 Jules3 0 Julie 30 On this Doc1.lst, I used sed to have only ...
1
vote
3answers
58 views

How to do find and replace in one field based on the value in the other field?

I have a file like this. IMS00|20140101|Unix|Jan14 IMS01|20140201|Unix|Feb14 IMS02|20140301|Unix|Mar14 IMS03|20140101|Unix|Jan14 IMS04|20140201|Unix|Feb14 My criteria are, if the column 1 value is ...