Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [sed]

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

1
vote
1answer
31 views

Move a line before another in a multi-command sed file

. I have a text file similar to this: A B C D E F G and I need to: move line E before line C; replace line C with X (X could be multiline); replace line G with Y (Y could be multiline); remove ...
-1
votes
0answers
47 views

finding words that contain only 3 characters using sed in a file

i need to print only words that consist of 3 characters, however the word document is a list (01.,02.,03. etc) this is what i have tried: [clf18ftf@sshgateway ~]$ cat animals | sed '/{[:lower:]].../...
0
votes
1answer
14 views

sed alters windows line endings unintentionally. How can I avoid that?

I am developing in linux a portable application, in which I wanted to remove trailing spaces from some source files, which have windows style line endings. The line endings should not be changed to ...
0
votes
1answer
18 views

Joining 2 files and excluding word from third file [on hold]

I have three files: file1, file2 and exl. Both file1 and file2 have two columns of content. The first column is the same in both files. I want to join the content of both files using that column. ...
2
votes
1answer
32 views

`sed` updates the meta dates of all accessed files

I used sed -i 's/oldpat/newpat/g' ~/mydir/**/*.txt to replace some str in some text files. However, the modified dates of all files, including those with contents unchanged, were changed to current ...
0
votes
2answers
20 views

Copy values from a file to a new file only after certain characters

I have a file with the following format: Reading frame 3000 time 30000.000 ^MReading frame 3000 time 30000.000 mu 8.788e+00 <mu> 2.945e-03 and I want to paste the values which are ...
5
votes
3answers
228 views

How to find and replace multiple field values using jq?

In the following json file, { "email": "xxx", "pass": "yyy", "contact": [ { "id": 111, "name": "AAA" } ], "lname": "YYY", "name": "AAA", "group": [ { "...
0
votes
1answer
40 views

How to find a particular key and replace the value in shell script?

I have a JSON file with the following text {"category": "yyy", "id": "xxxyyy", "environment": "fff", "client": "000000", "user": "Alex", "log_time": "xxx", "source_context": null} I need to find ...
0
votes
2answers
43 views

Find and replace a word in all files based on file pattern

I have a variable called "User": "x-73098" in multiple files and the file names like astro_root_sys-dev.txt. How to find all the files which have "User": "x-73098" variable and replace that ...
3
votes
5answers
220 views

sed on OS X - extract all text that is between square brackets

Given this stream: [foo] 123 [bar] [gar] dsa [har] 345 [uf] 88 [gc] 43 [br] I want to process this with sed (or anything else) so the output would be: foo bar gar har uf gc br I tried cat myfile | ...
0
votes
2answers
26 views

Replace different strings based on a match by a list of strings in another file

I have a file like this with tab delimiter: Chr1 mak gene 120221 120946 . + . ID=spa-h0003.02;Name=spa-h0003.02 Chr1 mak mRNA 120221 120946 . + . ...
6
votes
5answers
826 views

Making summary of sentences

I have data and I want to summarize sentences to generate conclusions. The example below is not related to the data, but just to clarify the idea so I can replicate it. Employee Suzie signed one time....
10
votes
2answers
1k views

Can you explain these three things in this bash code for me please?

I have a function in my .bashrc file and I can't wrap my head around it. I know what it does, it steps up X many directories with cd Here it is: up() { local d="" limit=$1 for ((i=1 ; i &...
-2
votes
1answer
29 views

To develope a list of unique names with sysdate [on hold]

I Have a file with ID’s and Names applicable to them as below: 1234|abc|cde|fgh 5678|ijk|abc|lmn 9101|cde|fgh|klm 1213|klm|abc|cde I need a file with only unique Names as a list. Output File: abc|...
1
vote
1answer
44 views

How to remove pattern from line but return what remains?

If I run ip addr sho | grep 9000 it returns the interface that I need quick stats for: eth3: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 9000 qdisc mq state UP qlen 1000 However, I'd like to ...
0
votes
0answers
36 views

bash script uses curl

sed -e 's/,$//' -e 'y/,/:/' test.txt | xargs -P 80 -I XX /usr/bin/curl -sk https://XX/ |grep phrase |printf "XX" it does not work for some reason. I need to do the curl and print the ip visited. The ...
0
votes
2answers
49 views

Organizing data by a header

I have two csv files. File 1 contains header. File 2 contains data file 1 format : file1.csv id,abc,xyz,aaa,bbb,ccc file 2 format : file2.csv id,source,value 1,abc,100 1,xyz,...
4
votes
2answers
186 views

Extract text between two characters (multiline input) [duplicate]

If I have the text: aaaaaaaaa #some info other rows end row# another info How could I extract only the text between the characters # obtaining only: some info other rows end row I was trying with ...
0
votes
4answers
42 views

unix sed remove adapter names

I would like to pipe the output to sed and remove the below adapter names using sed and group the values with commas ent13: 16 3979 ent12: 211 411 3978 ent11: 15 3977 ent10: 111 178 179 311 511 1719 ...
4
votes
3answers
157 views

Deleting portion of a text file and following lines using sed

I need to edit a file like the following: auto wlx00 allow-hotplug wlx00 iface wlx000 inet dhcp iface wlx000 inet6 auto post-up sysctl -w net.ipv6.conf.wlx000.accept_ra=2 auto wlx000 the goal is ...
0
votes
3answers
66 views

sed command to replace and write

I am trying to replace the following string with another one from a file which contains few lines. "schema" : "AAAAA", TO "schema" : "BBBBB", Currently, I am doing the following command to get the ...
2
votes
4answers
957 views

How to concatanate the result of two Linux commands

Is there an easy way to concatenate the result of two Linux commands, in one line (i.e., without using variables)? I pull the local outdoor temperature from a nearby weather station. The result ...
-4
votes
3answers
80 views

File Processing to transpose data [on hold]

I have a file with IDs and names applicable to them as below: 1234|abc|cde|fgh 5678|ijk|abc|lmn 9101|cde|fgh|klm 1213|klm|abc|cde I should get the output as different files having IDs matching each ...
0
votes
1answer
26 views

Extract substring after delimiter using GNU awk or awk [duplicate]

I would like to extract substring after colon delimiter for my practical needs using GNU awk utility. For example I can extract the temperature of hdd value using cut as follows hddtemp /dev/sda | ...
-1
votes
0answers
20 views

Regular expression to match only last folder [duplicate]

I would like to get the name of the last folder in a path for use in bash script. For example: I have a path /media/devicename/folder1/ I would like to get a variable called foldername that has in it ...
-1
votes
2answers
175 views

Add four lines between sentences [duplicate]

Is there an easy way to add four empty lines between each sentence. For example, this paragraph: This combination of vitamins and selected minerals is used to prevent or treat vitamin deficiency ...
1
vote
1answer
48 views

xargs plus shell string manipulation vs sed [duplicate]

I am trying to summarise the file extensions in a directory recursively. find .| xargs -d "\n" -I@ echo "${@##.*}" | sort |uniq -c But this is giving me a series of blank lines. Not what I wanted. ...
0
votes
3answers
65 views

How to split a file into paragraphs and name the resulting pieces based on an identifier present in each paragraph

I have a big file with more than 3264880 lines. I wanted to split that file based on Two strings "BEGIN JOB" and " END JOB" and write it into multiple files and the file name should be based on a ...
1
vote
3answers
292 views

Delete identical files saved as output in a log

I have three files in two folders. The files are named, a.txt, b.txt and c.txt were located in A and B folders. I have used an app Full File Mini Comparer which compares the folder and saves to log to ...
0
votes
0answers
17 views

IPv6 Seperate the IP address from port

From the following netstat output I need to seperate the IP address from the port with a comma. tcp6 0 0 :::22 :::* LISTEN 80823/sshd tcp6 0 ...
1
vote
4answers
55 views

How to move a line to the previous line if a certain character “ : ” is not found? [duplicate]

I have a lot of text files of transcripts. I have cleaned it to an extent. The last bit of cleaning is the following. I have this in certain files *.txt Gary: I said something. Larry: I said ...
0
votes
1answer
40 views

Using sed to replace periods with single spaces to periods with double spaces [duplicate]

What command would you give to print (display on the screen) the corrected text of userNotes.txt with all sentence endings having required two blanks before the start of the next sentence? This is ...
1
vote
1answer
23 views

edit names in phylogenetic tree in newick format [closed]

I have a phylogenetic tree in newick format, and I would like to remove some fragments of the name of the taxa, 1_[genus_specie_1]_characters:0.2654682758,(((((((((((((((2_[genus_specie_2]...
0
votes
2answers
43 views

Using bash to replace html character entities in the xml file

I have a string like this in xml file: &lt;h3&gt;Styled here with: &lt;a href="$url('Product-Show','pid','107723102')$"&gt;FRS blo&lt;/a&gt;, &lt;a href="$url('Product-...
6
votes
2answers
549 views

How to pop (read&remove) a line of a file?

I am trying to get the last line of a file and then delete it: Read the line: sed -n '$p' file # or tail -n 1 file Remove the line: sed -i '$d' file This works, but is there a way to do this with ...
0
votes
1answer
27 views

Replace values in a variable and retain new lines in BASH

This BASH script works as expected. I have a variable ($foo) that contains lines of data, I tell bash to separate at new lines, and I loop through the variable. #!/bin/bash foo=" Original Line1 ...
-1
votes
2answers
33 views

How to use sed to replace a word in a file with control characters [closed]

How to replace this word in a file globally which has control characters. how can i do that ? I have tried the below with no success. Replace "^Aabc_def_a^B" with "^Adef_a^B" globally Tried the ...
0
votes
3answers
44 views

adding a new line character to a row

I'd like to extract the 2nd field and transpose it to become a row cat > temp1 1 73 2 74 3 75 My approach : cut -f2 temp1 | tr '\n' '\t' > temp2 The result : temp2 73 74 75 ...
0
votes
3answers
108 views

Field separator part of a column - incorrect parsing unix

I want to do a check the number of columns in a CSV file before processing it. The problem is that the delimiter (comma) also occurs in the text of some fields and because of that I cannot parse it ...
1
vote
5answers
46 views

add file name as header of column

I have a directory with tables in txt format, and I'd like to add the file name as the header of the second column, for example: file_1.txt row_1 1 row_2 0 row_3 1 row_4 1 row_5 1 row_6 1 ...
0
votes
1answer
25 views

print lines before one pattern until a new pattern is found [duplicate]

First it should grep for Pattern_A, then print all lines before Pattern_A until Pattern_B is found(so basically it should search backwards) line1 line2 line3 line4 Pattern_B line5 ...
0
votes
2answers
45 views

what is wrong with sed while using words starting with “w”

This works echo " HELLO x=10" |sed 's/ *\HELLO \+/HELLO /g' removes continuous space before hello and after word "HELLO" but this doesn't echo " WHERE x=10" |sed 's/ *\WHERE \...
0
votes
3answers
59 views

How to extract second element from path? [duplicate]

How do I extract such pattern using sed? This is my path: /sample/xyz/logs/test.logs Output should be : xyz How is that possible if the path keeps changing for example like /example/xyz/log/test....
0
votes
2answers
30 views

How to use sed on all matching files?

I am trying to run sed on the output from find | grep \.ext$ However, sed requires input file and output file. How can I save the output line to a variable, or pass it to sed?
0
votes
3answers
48 views

extract paragraph match with words using sed or awk [duplicate]

I have file called "quota.txt" as below: DISK_info_start:/usr Disk: /usr CURRENT=81 DISK_info_end:/usr DISK_info_start:/usr/var Disk: /usr/tmp CURRENT=1 DISK_info_end:/usr/var I have a variable as ...
0
votes
0answers
21 views

aix extract fields from entstat command

I was collecting the SEA adapter and its related etherchannel and Network adapters status from the enstat command below. I want to extract the fields from the below command output. ETHERNET ...
2
votes
4answers
513 views

replacing comma with numbers in a string

I have text file contain strings like this abc,def,ghi,jkl,mno,pqr,stu,wxyz I want to make it like this 1.abc 2.def 3.ghi 4.jkl 5.mno 6.pqr 7.stu 8.wxyz how can i do that using sed?
0
votes
2answers
39 views

How to swap two fields inside a JSON file

I have a file like this {"100":["0.00001","10","0.01"], "101":["0.0001","100","0.1"], "102":["1","1000","1"], .... "103":["0.01","10000","10"]} I want to swap the second number with the third, ...
0
votes
1answer
24 views

Sed doesn't work as expected [duplicate]

I understand sed will Applies all instructions on line 1, then line 2... Previous instructions may change the pattern space so the next instruction will operate on that modified pattern space (...
1
vote
3answers
262 views

extract names from LDAP long names

I have this log file which observe user actions on the network, the file contain information from LDAP, very long list like this one: 2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com 2015-12-...