Questions tagged [sed]

1

votes
4

answer
68

Views

Replacing “../../../” using sed

I have a text file needs to edit. The first field contains the string '../../../' and I want to replace with '/home' . I tried using sed, but .. and / are special characters and I am a little bit stumbled how to match these patterns. I tried using something like (..), but it seems not working for...
Gu Buddy
2

votes
3

answer
76

Views

Set file modification time from the date string present in the filename

I'm restoring a number of archives with dates within their names, something along the lines of: user-2018.12.20.tar.xz user-2019.01.10.tar.xz user-2019.02.25.tar.xz user-2019.04.19.tar.xz ... I want to set each file's modification date to match the date in their filename by piping the filenames to t...
tobiasfried
1

votes
1

answer
19

Views

What does the range-operator in “sed” actually do, is it broken in GNU/busybox?

I wonder whether the GNU and BusyBox implementations of 'sed' may be broken. My default sed implementation is the one from GNU. POSIX says: An editing command with two addresses shall select the inclusive range from the first pattern space that matches the first address through the next pattern sp...
1

votes
3

answer
46

Views

Make sed regex alternations follow left to right precedence?

I'm trying to use a regex to format some binary from xxd -b, but to demonstrate this simply I'll show you what I expect to happen: Regex to delete: /1x|1.*/ Text: 1x21y3333333313333 -> 2 Where all occurrences of 1x are deleted, then everything starting at the first 1 that shows up should be deleted....
Unihedron
1

votes
1

answer
50

Views

Use sed to replace `,` within brackets

I'd like to replace commas within brackets with spaces (and also remove the brackets). I used sed, but the solution I could come up to is dependent on the elements in the list. sed 's/\[\(.*\), \(.*\)\]/\1 \2/g' # [-0.0, 1.23] => -0.0 1.23 (works) # [-0.0, 1.23, 4.56] => -0.0, 1.23 4.56 (doe...
orange
1

votes
3

answer
38

Views

Using sed to clean up SchemaSync output

I have created a small sample of what I'm working with at this point. I am trying to properly quote the DEFAULT values, specifically #2 DEFAULT ONE value should be quoted as DEFAULT 'ONE': #1 CREATE TABLE `table` (`column` int(10) unsigned DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=...
Rick
1

votes
2

answer
50

Views

Merge File1 with File2 (keep appending from File1 to File2 until no more rows)

I can't find a solution. So here is the problem. Result should be 100 rows (File1) with contents from File2 repeating 25 times. What I want is to join the contents even though the number of rows is not equal. Keep repeating including lines from File2 until number of rows from File1 is met. File1: te...
Jax
1

votes
2

answer
46

Views

RegEx for a multiple line search and replace using sed

I need to have a RegEx that finds a \n in the middle of a line as a start point, anything before is random, and replace after 15 digits and 49 alpha on the second line. I need to replace all that by blanks, but the second line needs to join with the first one. Attempt sed -r -e '{N;s/\n[[:digit:]]{1...
Eric Charbonneau
1

votes
2

answer
29

Views

sed using dollar sign for both environment variable and end-of-line pattern matching [duplicate]

This question already has an answer here: Using dollar sign in sed for both variable replacement and character 3 answers In sed, we use double quotes to read environment variable indicated by a dollar sign, what should i do if I want to use the dollar sign for end-of-line pattern at the same time?...
once
1

votes
3

answer
52

Views

need to clean file via SED or GREP

I have these files NotRequired.txt (having lines which need to be remove) Need2CleanSED.txt (big file , need to clean) Need2CleanGRP.txt (big file , need to clean) content: more NotRequired.txt [abc-xyz_pqr-pe2_123] [lon-abc-tkt_1202] [wat-7600-1_414] [indo-pak_isu-5_761] I am reading above fil...
Junipar70
1

votes
1

answer
20

Views

convert first column in a csv file from timestamp to year-month format

Trying to convert first column in a csv file from unix timestamp to date(year-month format) Tried date -d @number'+%Y-%m' and awk, but awk doesn't recognize @ when used together Extract from a csv file : 1556113878,60662402644292 1554090396,59547403093308 Expected O/p 2019-04,60662402644292 2019-03,...
Bt_code
1

votes
2

answer
32

Views

how to insert line break after a specific string?

I have a file with the following text, I want to make a line break, after the S. character i have this 1900-01-01 00:00:00|1|S|S|S|S.1900-01-01|S.1900-01-01 00:00:00|1|S|S|S|S.1900-01-01 00:00:00|1|S|S|S|S. i want 1900-01-01 00:00:00|1|S|S|S|S. 1900-01-01|S. 1900-01-01 00:00:00|1|S|S|S|S. 1900-01...
Brayan Pastor
0

votes
2

answer
19

Views

Manipulate AWK field variables ($1,$2,..) and add that to the end of line

I am trying to create /etc/host file from ansible inventory file. Ansible inventory file looks like this: [masters] k8s-master-a.example.com ansible_ssh_host=10.15.90.2 k8s-master-b.example.com ansible_ssh_host=10.15.90.3 k8s-master-c.example.com ansible_ssh_host=10.15.90.4 [etcd] k8s-etcd-a.examp...
bujail
1

votes
3

answer
79

Views

Replace text in every command-line argument, and pass it to another command

I have a big project I want to compile, but it uses some g++ flags that I don't want to use. Instead of editing Makefiles, I thought about writing small script, that would run be instead of compiler, process command line arguments and pass them to compiler. #!/bin/bash ~/g++ `echo '[email protected]' | sed 's/-Os/...
m132
1

votes
3

answer
13k

Views

unexpected EOF while looking for matching `'' while using sed

Yes this question has been asked many times, and in the answer it is said to us \ escape character before the single quote. In the below code it isn't working: LIST='(96634,IV14075295,TR14075685')' LIST=`echo $LIST | sed 's/,/AAA/g' ` echo $LIST # Output: (96634AAAIV14075295AAAT...
Bharat
1

votes
7

answer
93

Views

Replacing characters in each line on a file in linux

I have a file with different word in each line. My goal is to replace the first character to a capital letter and replace the 3rd character to '#'. For example:football will be exchanged to -> Foo#ball I tried thinking about using awk and sed.It didn't help me since (to my knowledge) sed needs an ex...
Ben Zoker
-1

votes
0

answer
16

Views

Making a new column out of specific lines from within a file?

I am trying to solve the following problem but several attempts have failed to get it right. Supposing I have the following in a file: a,b,c d,e,f g h I need some way to add g and h as a third column so that the file looks like this: a, b, c, g d, e, f, h Thanks for you help.
John Davy
0

votes
0

answer
6

Views

Sum of 2nd and 3rd column for same value in 1st column

I want to sum the value in column 2nd and 3rd column for same value in 1st column 1555971000 6 1 1555971000 0 2 1555971300 2 0 1555971300 3 0 Output would be like 1555971000 6 3 1555971300 5 0 I have tried below command awk -F' ' '{b[$2]+=$1} END { for (i in b) { print b[i],i } } ' but this seem...
Prince Garg
1

votes
2

answer
935

Views

Remove everything in a line before comma

I have multiple files with lines like: foo, 123456 bar, 654321 baz, 098765 I would like to remove everything on each line before (and including) the comma. Output would be: 123456 654321 098765 I attempted use the following after seeing something similar on another question, but the user didn't leav...
Melanie Shebel
1

votes
4

answer
77

Views

Get only third and sixth column from command output of pdffonts

I am using poppler pdffonts to get fonts in a pdf document. Below is the sample output $ pdffonts 'some.pdf' name type encoding emb sub uni object ID ------------------------------------ ----------------- ---------------- --- --- --- --------- Tim...
Satheesh K
1

votes
5

answer
67

Views

Grabbing a word and variable number of characters afterwards

I have a TAB separated file containing long strings, which I intend to filter the 8th column which has a mix of letters and characters randomly, to containing only ';OCCURRENCE=some words|' part as below: input.txt 1 138440 CAMEL C T . . MANY-WORDS-AND-CHARACTERS(*/-;|\);OCCURRENCE=HOY-BR|MANY-WORDS...
bapors
1

votes
2

answer
66

Views

How to search and replace with egrep and sed on macOS?

I want to match a pattern in a file and replace it. This command works with egrep, xargs and sed: egrep -lRZ 'hello' . | xargs -0 -l sed -i -e 's/hello/world/g' The problem: It does not work on MacOS because the xargs of MacOS does not support the argumente -l. xargs: illegal option -- l usage: xarg...
Alpha
1

votes
3

answer
70

Views

How to extract email headers extending on multiple lines from file

I am trying to extract the To header from an email file using sed on linux. The problem is that the To header could be on multiple lines. e.g: To: [email protected], [email protected], [email protected], [email protected], [email protected] Message-ID: I tried the following: sed -n -e '/^[Tt]...
Anis Bedhiafi
1

votes
5

answer
82

Views

sort text file by groups of 2 lines

I have a file with the following structure: A 35 74 dsadasd/1 0 + A 95 74 dsadasd/2 0 - B 75 159 dsadasd/2 0 + B 78 852 dsadasd/1 0 - C 12 789 dsadasd/1 0 + C 91 546 dsadasd/2 0 - A 87 52 dsadasd/2 0 + A 52 15 dsadasd/1 0 - I would like to...
Angel Garcia Campos
1

votes
2

answer
93

Views

sed regex: group repeat option?

I've got a text input with several group of lines. Each group is separated by an empty line (\n\n). I'm processing with sed, but I'm open to alternatives. I'm using this construct for being able to process all the lines at once: # if the first line copy the pattern to the hold buffer 1h # if not the...
kaefert
1

votes
5

answer
65

Views

Split 2nd occurrence of pattern of camel style text in sed

I am trying to create a key, value strings table for a mac app using sed and awk. So far I have got it to the point of having lines like: 'exif:DateTimeOriginal' = 'DateTimeOriginal:\t'; I want to do a final step to get: 'exif:DateTimeOriginal' = 'Date Time Original:\t'; In other words split up the...
Jim Merkel
1

votes
3

answer
43

Views

how to remove lines based on a number

I have a data like this >sp|Q96A73|P33MX_HUMAN Putative monooxygenase p33MONOX OS=Homo sapiens OX=9606 GN=KIAA1191 PE=1 SV=1 305 >sp|P13674|P4HA1_HUMAN Prolyl 4-hydroxylase subunit alpha-1 OS=Homo sapiens OX=9606 GN=P4HA1 PE=1 SV=2 534 >sp|Q7Z4N8|P4HA3_HUMAN Prolyl 4-hydroxylase subunit alpha-3 OS=...
Learner
1

votes
6

answer
105

Views

Script using sed and grep gives unintended output

I have a 'source.fasta' file that contains information in the following format: >TRINITY_DN80_c0_g1_i1 len=723 path=[700:0-350 1417:351-368 1045:369-722] [-1, 700, 1417, 1045, -2] CGTGGATAACACATAAGTCACTGTAATTTAAAAACTGTAGGACTTAGATCTCCTTTCTATATTTTTCTGATAACATATGGAACCCTGCCGATCATCCGATTTGTAATATACTTAACTGCT...
S.Chereddy
1

votes
3

answer
54

Views

How to remove space after the first pattern in sed

I have a file file.txt Name-6.1.4_Float Time;453802;464204;466345 464481 466131 464283 465065 462561 Name-6.1.4_Logic Good Time;125896;145349;137303 131601 144520 132487 133884 I want to replace the spaces between the numerical value by ; after the first semicolon ; The spaces between the numeri...
Arya
1

votes
2

answer
36

Views

Filtering Data in CSV file

I have CSV file in this format a,b,c,d,e,f,no disk detected a,b,c,d,e,f,disk run into error a,b,c,d,e,f,no memory in the server a,b,c,d,e,f,memory has correctable errors in the last column, I need to search for the word disk and replace it with disk error memory and replace it with a memory error T...
Prashant Lakhera
1

votes
3

answer
117

Views

How to delete content between text?

I want to delete all in all html files in all subfolders. I can't find the correct version of the line regular expression:
Canapsis
1

votes
6

answer
73

Views

How can I print only lines that are immediately preceeded by an empty line in a file using sed?

I have a text file with the following structure: bla1 bla2 bla3 bla4 bla5 So you can see that some lines of text are preceeded by an empty line. I understand that sed has the concept of two buffers, a pattern space buffer and a hold space buffer, so I'm guessing these need to come in to play here, b...
user2061575
1

votes
4

answer
272

Views

Reformat CSV file using awk

I have a file like this - 1,[test1] Joe,OK 2,[test2] Jack,OK 3,[test3] Tom,FAIL I am printing the file like this - cat file | awk -F',' '{ print '||' $1 '||' $2 '||' $3 '||' }' I would like the output file like this - || 1 || Joe || OK || || 2 || Jack || OK || || 3 || Tom || FAIL || i.e. [test...
Shraddha
1

votes
1

answer
28

Views

Generating new files from a template by finding and replacing, with bash

I have a template LaTeX file containing a counter (called 'Contador') inside the text, in a line such as \addplot[] table[]{figure-contador.csv} That counter allows me to include the data from a lot of figures coded in CSV files. The file is named test.tex. I want to generate 100 new files from...
Miley
1

votes
0

answer
119

Views

Add new column in file using sed

I am trying to add a new column in a file and using below command got from another Stack overflow post: sed 's/$col/$col$FSEP$value/' $file > ${file%.*}'_m.txt' col=1 is column number, value=20171231 is the and FSEP=| is the field seperator. current data: '01 '|'name '|'address '|' phone number...
Explorer
1

votes
1

answer
1.4k

Views

How to escape this sed command in a Jenkinsfile Pipeline?

I'm doing a simple substitution, and this works fine at the command line: sed 's/pub Url =.*/pub Url = 'https:\/\/example.com:3207';/g' myfile.ts I'm trying to run it within a Jenkinsfile, and like 40 builds later I cannot get the escape quoting right. Pretty sure it will look something like this:...
emmdee
1

votes
1

answer
85

Views

replacing all files with sed -i Argument list too long [closed]

I want to replace all files with sed -i. I want to replace word oldstring with newstring root-: sed -i 's| oldstring | newstring |g' * Argument list too long I have many files in the same dir. I want to replace all files strings. How can I solve this problem?
Sultan Alotaibi
1

votes
2

answer
41

Views

Sed append file is possibile use $?

I have this code: sed -i -e '$a\ persist.sys.timezone=Europe/Rome \ ro.miui.region=IT \ ro.miui.cust_variant=it \ ro.product.locale.language=it \ ro.product.locale.region=IT \ ro.product.mod_device=$DEVICE_NAME_miuita_global \ ro.miui.mcc=9998 \ ro.miui.mnc=9999 \ net.dns2=8.8.4.4' $BUILDPROP' He wo...
ale8530
1

votes
1

answer
46

Views

Bash: Appending different strings to specific lines in a file

let's say I have a file that looks like this: The Way Direct 5.0 0.0 3.0 2.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 2.0 3.0 4.0 6.0 0.000 1.000 2.000 1.0 2.0 3.0 4.0 5.0 6.0 3.0 2.0 0.0 I'd like to change this such that it looks like this: The Way Direct 5.0 0.0 3.0 U 2.0 0.0 0.0 U 0.0 0.0 1.0 U 0.0 0.0 2.0 U...
J. P.
1

votes
1

answer
66

Views

sh script to replace text in multiple files

I am trying to replace every occurrence in a .prm file of the string '/net/origin/devdata1/slin' with '/tools/common/test/HATS' in over a hundred files using sed. I think I am having trouble with the proper syntax for a for loop that loops through different files in a directory(/home/AutoTest), and...
dhboots

View additional questions