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

learn more… | top users | synonyms

0
votes
3answers
23 views

How to get second directory name in the perforce file path?

I need to get the directory in the second column after depot. For example given the below file(s) list, I need "Directory2" as the output. //depot/Directory2/Dir3/Dir4/Dir5/Dir6/Filename1 ...
0
votes
3answers
37 views

Extract a word from a line, doing this to a specific number of lines [closed]

I want to extract a word from a line, doing this to a specific number of lines. I have something like this. 1. Bill 2. Joe 1 3. Sue 1 I want to extract separately the words Bill, Joe and Sue. I ...
-3
votes
1answer
27 views

AWK interval expressions to clean IP [closed]

Credit to a great many entries from you online and manuals. It works, but, is it efficient enough? Do you approve? {Reading logs +- 5k items fast as I can see} Source data from file "myAwk3.txt": ...
0
votes
4answers
71 views

grep all strings that start with a certain char, and finish with another char

I need to grep all strings that start with "[" and finish with a certain string, e.g. "apal". So all chars in between these 2 chars would be shown as well. Given an input such as: ...
0
votes
1answer
42 views

Sed, Awk Multiline log file, a number {0-999] identify relation

Short version of issue: Need to extract from logs: {Using sed and awk on Linux} Time, PlayerName{Can have many special characters}, GUID, IP from log example at end. Longer version: How to combine 2 ...
0
votes
2answers
36 views

Sed incremental arithmetic

I want to replace a number at the end of a string by incrementing the number by one each time I run a specific sed line. the string looks like this: server-port=25555 I was thinking I could run ...
3
votes
1answer
134 views

Replace with sed until match in a line

I have to replace all "." characters before the "=" character in every line in a file. The lines are like this: one.two.three=something four.five=1 six.seven=127.0.0.1 ...
-2
votes
1answer
61 views

list of directories into comma separated directories [closed]

Hi I am trying to do scp copy of directories from one environment to another environment. Suppose directories at location \ as dir1 dir2 dir3 and so on. Now as the scp copy I need to list these as ...
-1
votes
3answers
50 views

How to swap two words with sed and with multiple delimiters?

Just letters are accepted in words, any other characters are delimiters. I want to exchange the first word with the third word. sed -E 's/([A-Za-z]+) [^A-Za-z] ([A-Za-z]+) [^A-Za-z] ([A-Za-z]+)/\3 \2 ...
1
vote
1answer
29 views

string substitution using sed

I have this string for example : asddsa "ll" sadd " fsgsg" "sdafaf" "lkkx" "fsgfgsg" I want to substitute all characters inside " " with a character x. Expected output in this case should be: ...
0
votes
2answers
37 views

Remove lines in a file where pattern only occurs once

I have a CSV file. It is ordered by an identifier the first field. The identifier in the first field can appear in either 1 or in 2 lines in the field. I want to remove all lines in the file where ...
1
vote
1answer
37 views

How can I get my bash script to remove the first n and last n lines from a variable?

I'm making a script to preform "dig ns google.com" and cut off the all of the result except for the answers section. So far I have: #!/bin/bash echo -n "Please enter the domain: " read d echo "You ...
0
votes
1answer
28 views

Substituting words in parenthesis using sed [duplicate]

I have a basic python script that looks like this: my_name = 'Zed' my_age = 35 my_height = 74 my_weight = 180 my_eyes = 'Blue' my_teeth = 'White' my_hair = 'Brown' print "let's talk about %s" % ...
1
vote
1answer
40 views

Using sed to replace spaces in text files with _ only when between “ ” after specific string

How can I use sed to substitute a space with an _ only when it occurs in a text file after the string title= and between " " For example (lines in a text file): title="This is the title of my book" ...
1
vote
2answers
37 views

Using sed to substitute a string containing variable integers

I have a text file and want to use sed to replace the following string (including the "s): " rel="lightbox[1846]" title=" with # The numbers between [ and ] are variable and change. I want to ...
0
votes
1answer
33 views

sed: replace only the first occurrence of wildcard

I am using sed to replace an attribute in an XML file and up until now it was working just fine. I have an XML file that contains a tag like this: <osgiApplication id="com.mycompany.site.app" ...
0
votes
3answers
17 views

find muli lines in file from other file

i have text file that have multi lines i wanna search for lines containing some text and add # at the start of those lines ex: file1 that i wanna change it acnet 6801/tcp # ...
0
votes
1answer
29 views

print only lines that starts with digit from specific column

I have a file which has second column as hostname of all hosts in my network: Host example.com (x.x.x.x) is up (0.0041s latency). And so on, but many lines doesn't start with hostname in second ...
0
votes
1answer
44 views

How to make sed as fast as grep when replacing values

If I search with grep in a 30 gig database for some values it finds all of them in no time, if I run the same command with sed to replace those values it takes ages. Why is grep so much faster than ...
3
votes
1answer
41 views

Combining every two column values in file

I have a file with (with only one line) with multiple columns say 4 (in this case) : A B C D And I want the output as every possible combination of column values taking 2 at a time like: AB AC AD ...
0
votes
1answer
31 views

Extract two lines following a line with a specific value

I have a text file and I would like to extract the two lines of data following a line containing only "Name" as a value. Name 032 Express intent to engage in diplomatic cooperation (such ...
2
votes
1answer
45 views

Better way to run a series of seven identical commands in sed? [duplicate]

In the post Sed - Replace first k instances of a word in a file, a user suggests: sed 's/old/new/;s/old/new/;s/old/new/;s/old/new/;s/old/new/' filename as a method of replacing the first k ...
2
votes
1answer
44 views

How to convert a timezone in logs as they are being tailed

I would like to manipulate the format of a datestamp from a log, in realtime, as it is being tailed. The current format is 2016-04-06T23:19:20.878Z. I would like to convert it to our local timezone ...
0
votes
2answers
35 views

backreference sed

i would like to capture as backreference something like this. Example: (a-z) But somehow anything I have tried, didn't work I try this: \(([a-z])\)\ or \('('[a-z]')'\)\
0
votes
2answers
43 views

Remove string with spaces and quotes from xml file

I would like to remove the string currencyId="GBP" from an xml file. Please note there is a single space before the first letter c. I am having trouble parsing the data and removing this string ...
0
votes
0answers
15 views

Dictionary - synonyms

I have czech czech-finnish dictionary and I have two czech synonyms in one row. Example: záchod (m); toaleta (f) WC; käymälä; miestenhuone; naistenhuone; vessa Synonyms are divided by semicolon ...
1
vote
4answers
28 views

Change dictionary from finnish-czech to czech finnish

I have this file http://sinivalkoiset.wz.cz/ostatni/finnish-czech.txt and I would like to swap first collumn with the second one. I used the sed commend sed -ne 's/\([^a-z A-Z].*\) \(.*\)$/\2 \1/ p' ...
1
vote
1answer
28 views

How can I pass the sed command output to variable without losing data format

I have a file with five lines with pipe separated data.Using sed command I am removing the pipe Only at the end of every line. But when I am passing below command output to a variable then data lose ...
-3
votes
1answer
34 views

How do i create a sed script to prompt the user to replace a number in a file? [duplicate]

I'm new in Unix, and I'm learning about sed command. I need to write a very small script for searching a number in a file and replacing it. I tried doing grep, and than deleting the specific phone ...
0
votes
2answers
44 views

return first instance of characters from a list

Lets say I have the output of this command saved to a file. cat /dev/urandom | tr -dc '[:graph:]' | fold -w 1000 | perl -pe 's/(.)(?=.*?\1)//g' | head -n 50 I would like to compare only the first n ...
0
votes
4answers
53 views

How do I insert the first line of one file into the first line of another?

I've got a head command to get the first line of a file and a sed command to insert before the first line of a file. How do I combine these so I can insert the extracted first line of one file before ...
0
votes
2answers
51 views

Piping sed/grep output does not work

If I run the commands bellow, only out1 has output, the out2 and out3 are empty. # this is just to generate a self-signed certificate openssl genrsa -out /tmp/ssl.key 2048 openssl req -sha256 -new ...
0
votes
3answers
45 views

How can i extract data from this line?

xyz /mnp/opq/p/1926081/sp/192608100/serveFlavor/entryId/0_ffx7sljc/v/2/flavorId/0_,n6h1xlhl,ea3anltg,jfs8boo9,w2v1vsk2,ze8e1q2s,to8w2p18,/forceproxy/true/name/new in this line this part ...
-1
votes
2answers
29 views

Need help in removing XML Tags with empty properties

Input File: <ServiceArea type="STATE" value="DC"> <DaylightSavingsUsed value="true"/> <FemtoSipProxyAddress value="10.13.123.100"/> <TermAuthAAAPSK ...
3
votes
2answers
81 views

Replace only in particular range string

In the canonical How can I replace a string in a file(s)? in 3. Replace only if the string is found in a certain context, I'm trying to implement the replace of a pipe with white spaces in file with ...
0
votes
3answers
91 views

Print start and end between two patterns excluding end of range [duplicate]

I want to use sed -n "/START PATTERN/,/END PATTERN/p" file.txt pattern to search in a file. file.txt content is ~keyword~, ~output~. ~1.~ ~output~. ~2.~ ~output~. ~keyword~, ~output~. ~1.~ ~output~. ...
3
votes
3answers
97 views

Replace multiple lines with a string when the line numbers are stored in a file

I have a file with few million lines, all the same. just for an example: Known Known Known Known Known Known ... I have another file with few thousand line numbers, for an example: 3 5 6 ... I ...
0
votes
1answer
33 views

How can i remove duplicates from the output of tshark output [duplicate]

sudo tshark -i ppp0 'tcp port 80 \ and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' \ -R'http.request.method == "GET" && http.request.uri contains ...
0
votes
1answer
33 views

I would like to erase the previous point of the multiple lines of text

I would like to erase the point of beginning point , as shown below. The name of the file aaa.txt. ./usr/share/vim/vim73/colors/blue.vim ./usr/share/vim/vim73/colors/default.vim ...
0
votes
2answers
51 views

Help in making multiple lines as single lines

I have below 4 lines: EXTRACT ETEST Last Started 2016-03-20 20:56 Status RUNNING Checkpoint Lag 00:00:02 (updated 00:00:04 ago) EXTRACT PTEST Initialized 2016-03-31 06:25 Status ...
2
votes
3answers
36 views

`pwd`, but omit first n directories

pwd gives the full path of the current directory, for example: /first/second/third/anotherdir/thefinaldirectory How can I omit the first n, let's say three directories, so that only ...
1
vote
3answers
34 views

Remove front-slash using sed

I have a text file that contains following https://git.centos.org/git/rpms/abc.git https://git.centos.org/git/rpms/abc.git/ https://git.centos.org/git/rpms/abc When I run the following command, ...
0
votes
1answer
44 views

sed cannot insert if a file ends with empty line

I have a file uca.xml (Thunar configuration for custom actions): <?xml encoding="UTF-8" version="1.0"?> <actions> <action> <!--some code--> </action> ...
0
votes
1answer
46 views

How to compare the strings using < (Greater than symbol)

Below is my input file: PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:16:46.523.177, 2 PS Sensor Value = -5.501000 , Min = -5.583000 , Max = -5.319000 ...
3
votes
1answer
125 views

how to use awk to do subtraction with numbers in a large file

I have a large file like this AT5G44030,TAACARA,1000,+,200,206 AT5G44030,TAACARA,1000,+,418,424 AT5G44030,TAACARA,1000,+,773,779 AT5G44030,NGATT,1000,+,114,118 AT5G44030,NGATT,1000,+,267,271 ...
1
vote
3answers
65 views

sed delete all besides first and last line of many files

I'd like to process many *.txt files in a directory - they have a common structure (; separated, common headers) but vary in the number of lines each is comprised of i.e. some are just a single line, ...
1
vote
2answers
49 views

SED Search and Replace on Linux [duplicate]

I want to change the value from 1521 to 1525 in FROM_HOST only in file gexhosts.cat: FROM_HOST db201521 TO_HOST db201521 Is there a way to do that or some work around? I would really prefer ...
0
votes
0answers
9 views

how to replace a string in vcf file which have a common charecter? [duplicate]

I want to replace any string which have the common charecter. like any string which have 1/1 in it will be completely replaced by "heteroV!" I have tried this command sed -iBAK2 ...
0
votes
2answers
91 views

Curl and Grep to Parsing Content

I need to parse the output of a curl command: curl --user test:test http://192.168.1.1/security/pkm.html | egrep '@company|config.pkm.password' This returns: <input type="text" ...
0
votes
3answers
31 views

Perform regex search on a previously regex-matched line (one-liner)

I need to print a string which is in a unique line in a long text file. Example relevant line in file long.txt: Software version 4.0.10, 2002-03-28 The wanted string is exactly 4.0.10. The steps ...