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

learn more… | top users | synonyms

0
votes
1answer
41 views

Use sed to edit code

How do I write a sed script that does the following: old(a,b) in the file should be replaced with new(b, 0, a) a,b can be any string with letters, spaces, digits, and these symbols: . / * - +
3
votes
3answers
69 views

How to use sed to write to a filename stored in a variable?

From within a bash script, how can I use sed to write to a file where the filename is stored in a bash variable? Output redirection won't do because I want to edit one file in place, pulling lines ...
-1
votes
2answers
49 views

First match if we are on the first line of input, if so print the whole line, else print the first word followed by a comma

for eg: CREATE TABLE MWWDATA.ACK997 ( AKTYPE CHAR(2) DEFAULT '' NOT NULL , AKNUM CHAR(9) DEFAULT '' NOT NULL ); CREATE TABLE MWWDATA.APREIDEXC ( EMPLID NUMBER(15, 0) DEFAULT NULL ); ...
0
votes
3answers
32 views

i want to print the line which starts with a paricular word and in the rest records print only 1st field

for eg: CREATE TABLE MWWDATA."VTCat02" ( "ID" NUMBER(10) DEFAULT NULL , "Cat" VARCHAR2(255) DEFAULT NULL , "Style_Code" VARCHAR2(255) DEFAULT NULL , "Vendor_Style_#" VARCHAR2(255) ...
2
votes
2answers
126 views

Refactor code using sed

How do I write a sed script the rearranges/refactors a string of characters of a file? The contents of my file are: for(int i=0; i<old(a, 10); i++) { sum += old(c*c, i*a) } ...
1
vote
4answers
72 views

How to get the number of each punctuation mark from a file

grep '[".?!"]' Returns the lines that have one of these but I have no clue how to tell how many are in each line, let alone how many ., ?, and ! there are.
1
vote
2answers
43 views

Use sed to format paragraphs for latex

I am using sed to reformat many plain text files to be compiled with LaTeX. The file contains various sections with keywords that provide a range. One of those sections I am working with is for ...
0
votes
2answers
61 views

Read a file and comment a line matching a string via shell script

Read a file and comment a line with matching a string via shell script I want to comment a matching line of file (final_ip) via shell script I have a input file (input_ip) if the searching ip is ...
3
votes
1answer
59 views

Replace Arbitrary Numbers of Word

Using sed, I want to replace patterns in the following way: --- >>> +++ --+-- >>> ++-++ --+-+-- >>> ++-+-++ --+-+-+-- ...
0
votes
1answer
137 views

Use sed replace with line number from variable

This is my sed command: while ...; do sed -r "${counter}s/^\S+ /$line /g" $in > $out; .. .. done Unfortunately this command isn't doing anything when called from within a bash script/loop. So I ...
3
votes
2answers
82 views

How to search for the word stored in the hold space with sed?

This is a sed-specific question; I am well aware it could be done with other tools but I am working on expanding my knowledge of sed. How can I use sed to globally quote (actually backtick) a word ...
0
votes
2answers
43 views

Combine rows from different files, if pattern is matched

Input: two tab-delimited files, File1 and File2. File2 ($2) has to be parsed by patterns found in File1 ($1). Expected output: tab-delimited file, File3. File3 has to contain the same rows as File2, ...
2
votes
3answers
237 views

unix: replace one entire column in one file with a single value from another file

I want to replace a column in one file with a single value from another file using unix. File 1 is a pdb file, structured like this: HETATM 14 H4B FAD B 600 95.544 50.240 71.308 1.00 ...
2
votes
5answers
491 views

Replace characters in user part of email address

I have a list that looks like this: user-name@domain.example user.name@domain.example user_name@domain.example ... I would like to replace any occurence of a dot in the username part. So that: ...
1
vote
0answers
23 views

line 24: unterminated `s' command assistance

I'm trying to get an sgml file processed using openjade and I keep getting this error: line 24: unterminated `s' command I'm not familiar enough with sed to figure out where there should be a ...
3
votes
1answer
32 views

Recursive find/replace, taking directory depth into consideration

I've had good luck doing basic find/replace: find . -name "*.php" -exec sed -i -e "s/<?php include 'http:\/\/www/<?php include '..\//g" \{\} \; I am wondering if there is a way to achieve a ...
2
votes
3answers
97 views

How to handle ^M in csv files by using sed & awk?

I have a file with delimiter ~, and was not able to load into database: Input file: 24~1~2~2~unsubscribed~wap~7~2015-10-23 20:03:00~2015-10-24 20:04:00~2015-10-25 02:53:26~Testing duplicate msisdn ...
1
vote
1answer
92 views

How can I run sed to replace lines in a file or do similar things in PHP?

I am writing a web frontend for configuring OpenWRT. I'm using PHP to execute commands and all the uci commands are executing without issues. However, OpenVPN configurations cannot be done via UCI and ...
2
votes
2answers
68 views

Are there any sed scripts built in to mainstream Linux distros?

When I was studying bash, I found it very helpful to go and study the bash scripts already present on a clean install of Linux—/etc/profile, for instance, and anything in /etc/rc.d/init.d/. These are ...
0
votes
1answer
46 views

Remove trailing spaces from first field only

I have a multi-lined, tab-delimited file like this: 99999bbbbbt999999bbt99t99t99t99 (where b=spaces, t=tabs) Trailing spaces in the 2nd field are ok, but the trailing spaces in the 1st field need ...
0
votes
2answers
41 views

Merge two lines of a file and adding number in the end of lines

I have a large text file abc.txt with the following format: BALT -6.110 130.600 4.06874414 -0.03254425 BALT -6.620 154.460 3.92286595 -0.17842244 BARM 32.740 140.680 3.94326190 -0.15802649 I need ...
7
votes
3answers
73 views

Remove certain characters from multiple files with whitepsaces

I'm trying to rename a bunch of music tracks in a directory, but I got this error: When moving multiple files, last argument must be a directory This is the script: for file in * ; do mv ...
1
vote
2answers
41 views

Extract keyword from line

I need to extract similar patterns from data below. The pattern starts with '.' or '' then to the keyword I want, then followed by ''. We can assume the format is LSUFE-numbers_ PCRF-numbers_ ...
4
votes
3answers
50 views

Inserting a text between 2 patterns

I have a .xml file which contains the below <controller-host></controller-host> <controller-port></controller-port> <tier-name></tier-name> ...
2
votes
3answers
331 views

Shellscript to remove particular tags in HTML file

Can anyone please guide me with writing Shell Script command for following scenario. I have an html file with all tags in a single line like this, ...
3
votes
3answers
76 views

How can I remove lines under a sub heading in a file using linux commands

I have a file as below . In which I want to remove lines under a particular sub heading alone. I tried using some sed and awk commands but I couldn't get it. Can any one help to crack this with some ...
0
votes
3answers
43 views

sed - How do I match this pattern?

I'm fairly new to using sed and I am having trouble finding out how to remove some of the first line of text from each block. Here is my original data: "s220823vaps2512": { "hostname": ...
1
vote
2answers
233 views

How can I print the second to last line of many files into one file? [duplicate]

I have many CSV files in one directory which have various lengths. I'd like to put the second to last line of each file into one file. I tried something like tail -2 * | head -1 > file.txt, then ...
0
votes
1answer
42 views

\1 - what does this sed action mean?

I am using this sed command to extract a json value for a key, say MyKey.. sedPattern='s/^.*"myKey":"\([^"]*\)".*$/\1/' For a json string like, {"myKey" : 1, "yourKey": 2} It returns what i ...
4
votes
3answers
847 views

How to grep lines between start and end pattern? [duplicate]

I have a file which is having following content: zdk aaa b12 cdn dke kdn Input1: aaa and cdn Output 1: aaa b12 cdn Input 2: zdk and dke Output 2: zdk aaa b12 cdn dke I could use below ...
0
votes
2answers
98 views

Prepend lines with file prefix using sed or awk

How do I change a sample input file so as to get something like the output file below? Input file: /tmp/logs 10/13/15 00:19:13 templogs1 10/13/15 00:19:13 dummylogs 10/13/15 01:19:12 test 10/13/15 ...
0
votes
2answers
71 views

sed command to comment out specific block of code containing search string [closed]

I have a listener.ora file for Oracle in which I need to comment out a block of lines specified by a search string, e.g., >(DESCRIPTION= >>(ADDRESS_LIST= ...
1
vote
1answer
38 views

stream editing tools: output what's scraped

I was just wondering if it was at all possible when using different stream editing and text processing/manipulation tools; such as grep, cut, sed, awk, perl etc. Are there ways to output (in the form ...
0
votes
0answers
22 views

In sed, what's the best way to apply blocks of commands to multiple addresses?

If I have a block of sed commands I want to apply to multiple addresses that aren't an address range, what is the best way to do this without repeating the block separately for each address? The only ...
0
votes
2answers
331 views

Shell Script to remove double quotes within the column value

I have a input text file with 10 columns, while processing this file, in one of the middle column, I am getting this type of data.I required column value to be as below: Input Column value: "This is ...
1
vote
2answers
47 views

awk regex for apache rewriterule

I have these variant of urls RewriteRule ^/trendy/the-reason-for-example/? http://www.example.com/trendy/the-reason [NC, L, R=301] RewriteRule ^/lol/2015/10..._for-example ...
3
votes
2answers
145 views

bash command that outputs the result of a previous pipe

I've got a text file outputted from a WebSpider. The Spider extracts all sentences from a given list of URLs. What I need to do is then process this file and find all lines that contain more than 65 ...
2
votes
4answers
150 views

Only leave longest line when first column is duplicate

INPUT: user@server:~/bar/foobar$ SAT=$(date -dsaturday +%Y-%m-%d); SUN=$(date -dsunday +%Y-%m-%d) user@server:~/bar/foobar$ awk 'BEGIN {FS="'^'"} {print $1"\t"$3"\t"$6}' STs.csv STt.csv | egrep -w ...
4
votes
3answers
141 views

Remove long string from files

Files on my server have been corrupted. I want to remove a 13000 character string from all PHP files containing it. The string looks like: ?php if(!isset($GLOBALS["\x61\156\x75\156\x61"])) { ...
0
votes
2answers
32 views

need to replace end of column with a character if it does not already exist

I am trying to use awk but can use anything else that will work lets say i have a file with these lines ewhueh wnlknlweknlnw/ qwejmdpdhhd 47578 enhkine enoekjohnkjiof elkjehbjuwekjuk 88989 ehnjkine ...
0
votes
3answers
69 views

sed command not replacing a text with newline character

The Unix sed command doesn't recognize a backslash escaped n \n as a newline character. For instance, the command sed "s!,!\n!g" is replacing commas in the input text with the letter n and not a ...
0
votes
1answer
92 views

SED find and replace element in filename with incremental values

A sample filename is Sample-0.0.1-SNAPSHOT.jar (result of a maven build in jenkins). My goal is to run a shell script that executes on failure and what that script does it adds incremental numbers to ...
0
votes
1answer
39 views

Can you replace displayed text with something else in command window?

I am trying to manage user accounts. They are basically just numbers, but I would rather see user last names on the screen. Is it possible to automatically replace displayed text with something else? ...
6
votes
2answers
338 views

Delete multiple lines in a file

Usually I find my answers in the previously answered questions, but not this time (or I don't understand the answers and can't modify them to do what I want them to do), so I'm asking my first ...
1
vote
1answer
53 views

sed - simple regular expression replacement not replacing

I'm trying to use sed to remove any subdomain prefix from a list of hostnames, but it's not replacing anything when I use a regular expression. Here's the simplified example that's not working: echo ...
4
votes
6answers
153 views

Make longer strings from substrings keeping new line between each string

I have a file that contains strings as: GTACGACGGAGTGTTATAAGATGGGAAATCGGATACCAGATGAAATTGTGGATCGGTGCAAAA GTCGGCAGATATCGTTGAAGTCATAGGTGATTATGTTCAATTAAAGAAGCAAGGCCGAAACTAC ...
3
votes
3answers
71 views

Passing variables to the sed command,

We have a file containing 6 columns. FILEDESCRIPTOR . DESCR00001 FILEDESCRIPTOR . DESCRIPTIVENAME FILEDESCRIPTOR . LSTUPDNAM FILEDESCRIPTOR . LASTUPDATENAME FILEDESCRIPTOR . LOCAT00001 ...
0
votes
1answer
44 views

Search for a pattern in a file and move it to the new files one by one

I am trying to search for a particular pattern in a file and move it to a new files one by one. I am a noob and I tried sed -n 's/CREATE PROCEDURE/,/END ;/p' File It is again printing the same file. ...
0
votes
1answer
24 views

Using xargs to generate links

I have a file that looks like this: abc,123,x xabc,345,xy cabc,6234,ab abgc,12,yo jabc,9991,to I need to generate a list of links: http://www.mywebsite.com?param1=abc&param2=123&param3=x ...
1
vote
4answers
132 views

Trying to grep url from html source in .txt file using sed

i have been able to use the code below to grep lists of urls from html source before, but for some reason it's not working for this specific example. grep: grep -1 box-download shareit1.txt|sed ...