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

learn more… | top users | synonyms

1
vote
1answer
65 views

What can I know about this part of code? [duplicate]

What does this part of a script do? This is a part of a scrpt in bash for j in *.* ; do cp $j ../../$name-S$i.gid/data/${j%%.*}$i.${j#*.} sed "s/$name-S/$name-S$i/" $j > ...
1
vote
2answers
82 views

Regular expression find 3 or 4 numbers

So, I have 50+ words and I have to match the numbers in them. These numbers can be 3 or 4 digit numbers. I think I tried every way there is, but nothing seems to work (I need to remember the number as ...
0
votes
1answer
61 views

Search for pattern across multiple files and replace a sub-part in all occurences

I am helping a friend with her thesis written in LaTeX and I need a quick solution for a "search and replace". Using a terminal in Linux, how can I find the following pattern: \caption{*\cite{*}} ...
1
vote
3answers
631 views

Delete lines from a file using awk or sed based on the variable from previous command

I have a CSV file (say temp.csv) with strings and numbers. I need to delete the lines which contain a particular pattern of string at the beginning of the lines in the file. For example, here is my ...
2
votes
1answer
40 views

How to ensure that string interpolated into `sed` substitution escapes all metachars

I have a script that reads a text stream and generates a file of sed commands that is later run with sed -f. The generated sed commands are like: ...
6
votes
3answers
360 views

Remove only the commas present within the double quotes

In a text file, I want to remove , (commas) and also the " (quotes) (only if the double quotes contains numbers seperated by commas). 56,72,"12,34,54",x,y,"foo,a,b,bar" Expected ouput ...
2
votes
1answer
54 views

How can I use a back-reference in place of a filename in sed?

I am trying to use sed to scan through a file and find a pattern, then use part of the matched pattern as a filename and insert the contents of the file at that location. I can get most of it to work, ...
0
votes
1answer
102 views

bash using grep and sed

This is for our weekly prac, no marking or grade (we don't even get the answers!) I'd really appreciate it if anyone has the time to help explain this exercise to me, as I'm trying to get this work ...
3
votes
1answer
189 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
82 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
55 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
83 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
52 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
74 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
86 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
35 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
54 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
85 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 -- ...
1
vote
2answers
153 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
236 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
124 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
276 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
137 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
318 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
156 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
116 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
470 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
73 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
70 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
75 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
164 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
58 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
252 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
44 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 ...
7
votes
5answers
365 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
120 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
348 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
68 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
42 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
176 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
168 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
135 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
45 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
993 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
80 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
117 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
32 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
238 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
517 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 ...