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

learn more… | top users | synonyms

3
votes
1answer
252 views

Fastest `uniq` tool in linux

I have large text file (1.5 G), I want to know what the fastest and more reliable tool in linux is. I usualy use: awk '!x[$0]++' file.txt But when I use htop command I see my memory usage is ...
0
votes
1answer
204 views

Escaping multiple backticks in a sed call

I need to perform search and replacement iteratively in several SQL statements: From: CREATE TABLE `Old_Name` ( To: ALTER TABLE `Old_Name` RENAME TO `New_Name` The above query contains ...
0
votes
1answer
79 views

Using eval and sed to perform counting and script control

Following the original issue described here:- Rip chapters of a DVD to separate files ..would someone help us understand what the following code is doing:- # count Titles, and count Cells per title. ...
1
vote
2answers
156 views

How to mark dates which are in the past?

From the answers I updated the question: Now, it's: $ date "+%F %H:%M" 2014-06-04 11:26 This is the input: $ cat input.txt <tr><td>2014-04-24 14:01</td><td>2014-06-04 ...
1
vote
2answers
113 views

How can I comment out snmpmibd and snmpd in rc.tcpip in AIX using sed?

I need to comment out an entry in rc.tcpip file inside /etc # Start up the snmpmibd daemon start /usr/sbin/snmpmibd "$src_running" # Start up the Simple Network Management Protocol (SNMP) ...
2
votes
2answers
127 views

Sed? Stripping all formatting, i.e line breaks and whitespaces, from a report text file, while masking out certain pieces

I am working on a project in which I need to remove all formatting from a text file including whitespaces and line breaks, then replace any colons with pipes. I've made some headway but I cannot find ...
0
votes
2answers
105 views

How can I use Unix to rename all html files by their titles?

As in, rename all HTML files in a directory by the text contained in TEXT? Could a combination of grep, sed, and mv work? For example, I have a file contained 1.html. The title of 1.html is ...
0
votes
3answers
42 views

Using sed to perform substitutions in a file

I was trying to replace dates in a huge file using sed. I tried : sed -ie 's/2014-[0-9]{2}-[0-9]{2}/2014-05-07/g' test However, nothing happened at all, my file test is not modified. Do you know ...
0
votes
2answers
98 views

Method to paste specific column when in terminal

I'd like to paste only the third column of data from within the terminal. I originally have something like: 4 SF0086 SF0086 12 SF0087 SF0087 17 TSF141 TSF141 29 TSF070 TSF070 30 TSF028 TSF028 31 ...
1
vote
4answers
92 views

How to delete a line if string is the only thing on the line

How can I use sed or something else to delete a line only if the string I'm searching for is the only thing on the line? Example output: device-address-binding: ? database-revision: 20 -- ...
2
votes
2answers
586 views

How to search and replace strings matching a replacement list for multiple files

I have a file, say map.txt, containing a list of search strings and corresponding replacements: search -> replacement bigBone -> bb fishMarket -> fm dogCollar -> dc ... I need to ...
2
votes
6answers
356 views

How to search, replace and append a pattern to the end of each line

I have the following list of items: bigBone fishMarket dogCollar ... I need to generate a two character mapping like this: bigBone -> bb fishMarket -> fm dogCollar -> dc ... How can I ...
2
votes
4answers
312 views

How to sed -e 's///' everything except a specific pattern?

How can I substitute everything in a string with sed except % and any number directly succeding it? Meaning, everything except strings such as: %1 %1000 %55 etc. Best @devnull pointed out that ...
2
votes
2answers
745 views

How to add a string with spaces at the end of command output

I want to add a string with spaces at the end of each line of the output of ls command. #!/bin/sh STRING_WITH_SPACES="this should be at the end of output" ls -lh | sed 's|$| '$STRING_WITH_SPACES'|' ...
0
votes
1answer
244 views

How do I use the SED command to remove injected code from multiple files?

One of the domains on my Centos 6.5 (64 bit) server has been compromised. Having run a detection script on the public_html folder I have identified all the files with this code injection. I ...
4
votes
7answers
331 views

How can I groups numbers in a file

I have a file with numbers in float format. I can review them via sort -rn numbers.txt | less I would like though to be able to "group" them. I.e. easily see how many are in the same range. To give an ...
2
votes
2answers
204 views

How can I extract the numbers in the file using sed or any other tool?

I have a file that has this format [ 2014/05/01 10:48:26 | 13963 | DEBUG ] It took 11.16837501525879 seconds to complete the process So I have thousands of lines like this and I would like ...
1
vote
1answer
127 views

Parse/Manipulate in awk

I am new to awk programming. I have a question on manipulating text file, which is required to draw certain network based images in a visualization software (Circos http://circos.ca) I have input ...
3
votes
6answers
986 views

Remove last comma from a bash for loop generated string

I am dealing with a situation where I need to create a comma separated list from an array into a heredoc and remove the last comma. I am using bash for piped into sed which is erasing all commas ...
10
votes
9answers
1k views

How can I print the longest number in a string?

I am looking for a method to print the longest number in a string. E.g.: If I have the string 212334123434test233 how can I print 212334123434 ? Note: I am looking for the longest continuous ...
1
vote
3answers
79 views

Are there any difference using pipes?

Using Ubuntu 12.04. Using pipes (5 times): $ time echo XYZ | sed 's/X/A/g' | sed 's/Y/B/g' | sed 's/Z/C/g' ABC real 0m0.005s user 0m0.000s sys 0m0.000s $ time echo XYZ | sed 's/X/A/g' | sed ...
1
vote
2answers
73 views

Parse,Manipulate Data In linux/Unix

I want to have exactly the same output in this post(http://unix.stackexchange.com/questions/126139/extract-data-in-linux-unix)as above,but I have a new input file,which is below: ABCB11 4 ACE 11 ...
-5
votes
2answers
168 views

Replace words in file using sed command

I have a file z. I want to replace string in File using sed command: 123: ' ', to: 123: '456',
1
vote
2answers
174 views

Extract data in linux/unix

I have input data which I want to parse and extract values using awk/grep/sed: group-2 9 10 text color=black,from=ABCB11,fromid=4,order=2,thickness=3,to=ACE,toid=11,use=1,z=1 group-3 0 1 text ...
-2
votes
1answer
85 views

Comment multiple line using SED

Seeking help how can i comment multiple lines using SED, i like to comment ftp, telnet, shell, time, ntalk, daytime in inetd.conf file. Thanks in advance
1
vote
5answers
293 views

Replacing backslashes with commas in Bash

I tried writing a script in which I am reading through a file line-by-line. I am supposed to replace a backslash (\) with a comma (,). The input file is as follows: 1,2,3,WORKSTATION1\A,5 ...
0
votes
1answer
49 views

How can I print a specific occurence of a range pattern?

I am trying to extract several data fields out of somewhat peculiarly formatted strings. Each string has a format similar to the following (spaces added for emphasis): 1 abcd 2 1 efg 2 hij 3 ...
8
votes
5answers
943 views

SED : Case Match Pattern Replacement

I have a source code spread across several files. It has a pattern abcdef which I need to replace with pqrstuvxyz. The pattern could be Abcdef (Sentence Case) then it needs to be replaced with ...
2
votes
1answer
147 views

How can I make my sed command work on OSX as well as Ubuntu

I like customizing my PS1 prompt and including the current directory. I also have several other items such as time, user, git branch and the like, i.e. However one problem is that when my current ...
3
votes
2answers
1k views

How can I print out all but the last n characters in bash?

I'm working with standard input (cating two files together) and want all but the last 10 characters of the result to be passed through the next command. All I can find through searching is using sed, ...
0
votes
1answer
164 views

Want to replace the words with space in multiple files using SED commmand [closed]

Want to replace the words with space in multiple files using SED commmand I have a word as 'Danny' with single quotes in many of my files in multiple directories which I want to change to 'Danny ...
0
votes
1answer
68 views

removing the last line of a file not working? [duplicate]

I have this TXT file that is created by a bash script and at the end I want to remove the last line of that file that is an empty one. head --lines=-1 r3.txt > r4.txt sed '$d' r3.txt > r4.txt ...
3
votes
3answers
228 views

Rearrange text file by prepending data rows with header row

I have a file whose content looks like this: 2009 150 0 0 0 0000 75.316 0.0400390625 0.00007 0.00000 0.8980 76.216 0.0400390625 0.00007 1.00000 0.9046 77.217 0.0400390625 ...
5
votes
3answers
180 views

Extracting data from complex file structure

I have a txt file that is a dump from a database, that contains one entry per line. The structure is like this: 1500 29/03/2010 18 02 09 47 17 45 28.248 0 0.01 130 12.721 7908 298,809 YES ...
3
votes
6answers
334 views

sed remove characters from new line

After some processing, I have my input file like below. file1.txt 12345|john|student 43321|jack|professor 78965|alex|lecturer I need to process the above file further and so I need a line ...
-2
votes
1answer
52 views

sed query for pattern matching [closed]

My file looks like cat new: ALL ALLOFTHEM ALL1 OPS BE2A OPS1 ABE ABE ABE1 sed query below gives me the result as 1st line sed -n '/\([A-Z]\{1,\}\)\1/p' new: ALL ...
6
votes
4answers
3k views

How to extract logs between two time stamps

I want to extract all logs between two timestamps. Some lines may not have the timestamp, but I want those lines also. In short, I want every line that falls under two time stamps. My log structure ...
0
votes
2answers
126 views

Extracting with grep/sed a first pattern and then a second pattern that occured some lines before and related to the first

I'm trying to extract a specific line from a .htm file when a pattern occur ("Event 100" in my example below) but at the same time I need to retrieve also another pattern which is related to the first ...
1
vote
5answers
288 views

How to remove lines shorter than XY?

I found a question about, how to remove lines longer then 2048 chars: How to delete line if longer than XY? Q: But how can I remove lines shorter then 4 chars? So remove lines that has 1 or 2 or 3 ...
1
vote
1answer
35 views

Text pre-processing How to run many scripts at once

I have many scripts for text cleaning, is there a way to execute all of them at once instead of doing that one by one, for example I have : sed -i -r "s/[’'–]/ /g" *.txt sed -i 's/Aβ/ ABeta /g' ...
1
vote
2answers
554 views

How to replace a custom date string in a text file

I've looked through several tutorials and a couple of StackOverflow posts, but I've not seen any examples using sed or awk which use dates. I have a text file that contains this as the first line, I ...
4
votes
7answers
562 views

How to split a filename list in 5GB sets?

I have a pretty big list of files which I like to group in smaller list of 5GB each for further processing. The file list is in the following form: "size" (from du) "tab" "absolute path", like this ...
3
votes
4answers
343 views

extract the characters before () using grep

I need to extract the characters before the character '('. My file structure is: rose(good)ook daisy()no lilly(bad)fine sunflower()nice I need output file as in the form of: rose ...
1
vote
3answers
70 views

awk want to total by hour and variable

I am able to run this and it works fine - note: field $1 is a time/date stamped field.. gawk -F ":" "{ print $1 }" /cygdrive/c/counting/ourlog | sort | uniq -c | sort -r 57339 2014-03-21 09 54290 ...
1
vote
1answer
69 views

Remove the string before the whitespace

I want to remove a word before the whitespace. My file structure is: ant tiger static rabbit lion dynamic monkey donkey I need the output as: ant tiger rabbit lion monkey donkey ...
5
votes
4answers
479 views

Reduce the over use of files in text processing

Currently, I have a file (Results.txt) which has 27k rows. The file content is as below. 45008657 | A. | | Long | 0 49210987 | A. | ...
2
votes
3answers
95 views

sed: what does “/ ” mean?

x=`src/lstat64 $TEST_DIR/$tmp.1 | sed -n -e '/ Links: /s/.*Links: *//p'` In this script. I understand this part "/s/.*Links: *//p'" the only thing I don't understand is '/ Links: ' what does "/ " ...
5
votes
2answers
190 views

sed replace only lines with matching groups

Currently, I have this command: sed 's/\([^C]*\)/\1AB/' It inserts "AB" before the first instance of "C" on a line. But it is also adding "AB" at the end of every line without a "C". How can I ...
3
votes
3answers
599 views

Regex not matching

why this does not match..? sed -e '/--Updated?[[:space:]]+Date/d' inputfile this..: --Updated Date: 2013-11-06 15:32:13 d? is because sometimes I have Update Date, and sometimes Updated Date. ...
1
vote
3answers
1k views

Extract part of string using grep

I have 3 files in a directory MYO144064T MYO144064TA MYO144064TX Where the digits and 11th character will change. In my csh script, I want to extract the letters 'A' and 'X' probably using grep ...