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

learn more… | top users | synonyms

1
vote
3answers
290 views

Why is '1,4p' outputing all the lines instead of just the first four?

I have a text file called "list" which contains some random words: he she we his her with his this this -- this this I ran this sed command: sed '1,4p' list What I thought this sed command was ...
1
vote
2answers
51 views

Insert line after matching line in sshd inside pam.d

I want to insert a line after matching line in sshd file which is present inside pam.d directory. For e.g. it should search for this line account required pam_nologin.so and it should ...
3
votes
2answers
647 views

how to grep for specific time period in a log

We work with log files that have line entries that start with a date/time format such as this: 20150408 13:29:28 <rest of text> What would I need to do in order to grep for a date range? Say ...
0
votes
1answer
37 views

seeking hints for correct escaping of sed commands WITHIN yaml

I am having a hard time finding the issue why following lines of "code" break my cloud-init config. Basically I am calling a son object as part of the DigitalOcean API which has a YAML format - I got ...
2
votes
3answers
215 views

How to 'drop' characters from in front of a string?

I have a string that I would like to manipulate. The string is H08W2345678 how would I be able to manipulate it so the output is just W2345678? Similarly if the I wanted to drop the last 4 ...
0
votes
2answers
44 views

How to scrape multiple IP's and add in a script as a variable?

I am trying to add in my script an awk statement or a: if; else; then if eth0:4 is a match then put in eth0:4 IP How would you get the IP in your script as a variable if you have multiple IP's ...
4
votes
3answers
139 views

Remove duplicate lines while keeping the order of the lines

[root@server]# awk '!seen[$0]++' out.txt > cleaned awk: (FILENAME=out.txt FNR=8547098) fatal error: internal error Aborted [root@server]# The ""server"" has: 8 GByte RAM + 16 GByte SWAP, x>300 ...
3
votes
4answers
247 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
103 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
83 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
207 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
40 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
158 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
75 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
408 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
56 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
70 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
51 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
59 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
72 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
223 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
71 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
57 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
63 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
44 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
53 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
108 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
41 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" ...
2
votes
1answer
68 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/' ...
2
votes
1answer
53 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
75 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
115 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
203 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
232 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
56 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
54 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" ...
3
votes
1answer
128 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
71 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
193 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 ...
1
vote
3answers
217 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
338 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
86 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
86 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
2answers
77 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
84 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
60 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' ...