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

learn more… | top users | synonyms

1
vote
1answer
39 views

display users that logged in since a date using last

I am trying to display the user name of the accounts that have logged in during the past month using the last command. At the moment I have this last | awk '{print $1, $4 ,$5 ,$6}' | grep -B 10 Jul |...
2
votes
2answers
156 views

Delete row if two patterns are found in the same line

I'd like to delete a line from a text file (input.txt) if two patterns (string1and string2) are found on the same row, using sed. I'm trying: sed -i "/\b\(string1\|string2\)\b/d" input.txt, but ...
-1
votes
1answer
30 views

Reformat text contents into a CSV

I have a text file that I wish to turn into a CSV. The pattern of its contents are as follows: 1 mm/dd/yyyy LastName, FirstName MiddleName ID-NUMBER-HERE GENDER 2 mm/dd/yyyy LastName, FirstName ...
1
vote
2answers
111 views

Combine xargs -I with sed

I want to use find to find certain files and then use xargs with cp and sed to move these files to another folder and rename them. I know how to do this in a loop, but that is not what I am looking ...
0
votes
3answers
203 views

Use Command Line Argument and Variable with sed Inside Bash Script

I have a bash script that takes a bunch of command line arguments. The only one that matters in this context is the first, $1, which is a text file. The header is very long, below are examples of ...
2
votes
4answers
50 views

How to append a line that does not start with '<' to the previous line

I have a log which contains XML lines. Sample format below: <head> <body> <line> asdasd</line> </body> </head> I want to scan the log file and ...
1
vote
3answers
77 views

sed doesn't distinguish between full regex match and no match

I want to extract portion of a string matching a regex. Consider the following code that works correctly: regex="ss" string="blossom" echo $string | sed "s/^.*\($regex\).*$/\1/" Output is: ss ...
0
votes
2answers
73 views

Problems with regex in grep

I'm trying to remove malware code from a site using a script, I'm having trouble getting the regex right for the malware part. What I want to do eventually is to use sed in order to find the ...
2
votes
1answer
85 views

sed regex for capture group between delimeters

I have a two line file that I'm trying to get some info out of for a bash script using sed. # File Comment PrefixForInformation {information to be captured} I need to get the information between ...
1
vote
1answer
61 views

How to replace string in files using asterisk in search form

In my log files (*.log) I want to replace all occurrence of: "INFO=*", to "INFO=*;;;", where * could be anything. So, for example, "INFO=1234",S -> "INFO=1234;;;",S Is there a way how to do it ...
2
votes
3answers
207 views

How can I delete everything between two markers in a file?

I have a text in a text file, where I want everything that is between strings like \{{[} and {]}\} to be deleted - including these strings themselves. These two string can lie on different lines as ...
2
votes
1answer
35 views

need help with awk merging rows by sequence from multiple files into one file

have alot of files and need to merge strings between themself by groups of three files. each file ~100-500 rows and result file ~100-200mb seems like awk or sed can help me with paste or without it or ...
4
votes
3answers
168 views

How to match a pattern, delete the pattern and also the next and the previous line on Solaris 10

How can I match a pattern, delete the pattern and also the next and the previous line on Solaris 10? I'm hiting the wall because Solaris does not come with GNU sed. Given the following file content: ...
1
vote
1answer
63 views

sed, getting an error:sed: unterminated {

I'm using below sed command sed -n '\|<tag>|{:n; \|</tag>|!{N;bn}; y|\n| |;p }' test.xml OUTPUT: <tag> <name>jolly</name> <class>2nd</class> <address&...
0
votes
1answer
45 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
149 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
56 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
36 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
167 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
126 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
47 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 ...
1
vote
2answers
92 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
67 views

Replace Arbitrary Numbers of Word

Using sed, I want to replace patterns in the following way: --- >>> +++ --+-- >>> ++-++ --+-+-- >>> ++-+-++ --+-+-+-- >&...
0
votes
1answer
263 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
95 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
50 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
712 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 -1....
2
votes
5answers
640 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
29 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
59 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
198 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
234 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
74 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
71 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
43 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
111 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
51 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
55 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> <node-name></...
2
votes
3answers
482 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, <html><head></head><body>&...
3
votes
3answers
91 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
48 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
620 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
68 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 need,...
4
votes
3answers
3k 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
143 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
93 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= >>>(ADDRESS=(PROTOCOL=tcp)(...
1
vote
1answer
47 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
24 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
1k 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 ...
4
votes
2answers
167 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 ...