sed

Delete a whole word from a CSV file that is not part of another word using SED

Delete a whole word from a CSV file that is not part of another word using SED I’ve searched for an answer to this and have come close, but not close enough. We receive a CSV file that contains the text "NULL" which needs to be replaced by nothing. Example: Input 12345,George,MCNULLMAN,NULL,green,NULL Replacement should result …

Total answers: 4

How to modify a gzipped file with sed and then zip again the file?

How to modify a gzipped file with sed and then zip again the file? I have a .vcf.gz file, with the following aspect: #CHROM POS ID REF ALT chr1 10894 chr1:10894:G:A G A chr1 10915 chr1:10915:G:A G A chr1 10930 chr1:10930:G:A G A I want to modify the CHROM column to remove ‘chr’ and to …

Total answers: 2

awk on date conditions

awk on date conditions I am trying delete rows from a person.csv (below) for the condition that person who are not born in last 1 year: Dataset1: "Index","User Id","First Name","Last Name","Date of birth","Job Title" "1","9E39Bfc4fdcc44e","new, Diamond","Dudley","06 Dec 1945","Photographer" "3","32C079F2Bad7e6F","Ethan","Hanson","08 Mar 2014","Actuary" "2","aaaaaaa, bbbbbb","Grace","Huerta","21 Jan 2023","Visual merchandiser" So, the expected output would look like(last row got …

Total answers: 5

sed: update 2 similar variables in a file but keep the upper and lowercase

sed: update 2 similar variables in a file but keep the upper and lowercase I have 2 variables in a file like below that I need to assign a new value inserted by one user input: read -p "Enter CName Name : " CName sid=C02SBX SID=C02SBX When I run the following GNU sed statement: sed …

Total answers: 2

Use SED to replace part of a current variable with user input variable

Use SED to replace part of a current variable with user input variable I’m trying to replace only part of the existing variable with a new user input variable as below: #Current Variable: gdbName=Test.MY.DOMAIN.COM <–I need to replace the "Test" (This can be any other string not just Test e.g. CDB79 etc.) part only in …

Total answers: 2

Remove duplicates by adding numerical suffix

Remove duplicates by adding numerical suffix How do I append a numerical suffix to lines to remove duplicates? Pseudo code: if currLine.startsWith("tag:") x = numFutureLinesMatching(currLine) if (x > 0) currLine = currLine + ${x:01} Input file tag:20230901-FAT val:1034 tag:20230901-FAT val:1500 tag:20230901-LAX val:8934 tag:20230901-SMF val:2954 tag:20230901-LAX val:1000 tag:20230901-FAT val:1500 Desired output tag:20230901-FAT-02 val:1034 tag:20230901-FAT-01 val:1500 tag:20230901-LAX-01 …

Total answers: 4

awk add a column if it doesn't exist

awk add a column if it doesn't exist I would like to add a column 3 (description) if it does not exist in a ‘;’ delimited file. example; #Gene;Transcripts;Description;Group gene1;G1a,G1b,G1c;gene1 is a good gene;6 gene2;G2a,G2b,G2c;gene2 is a funny gene;3 gene3;G3a,G3b;4 gene4;G4a;gene4 description;5 gene5;G5a,G5b;6 Expected output #Gene;Transcripts;Description;Group gene1;G1a,G1b,G1c;gene1 is a good gene;6 gene2;G2a,G2b,G2c;gene2 is a funny …

Total answers: 4

How to remove empty lines containing only ends of lines $?

How to remove empty lines containing only ends of lines $? I have a file: cat -E extracted_numbers.txt 11.47$ 0.32$ $ 1.37192$ -4.$ 7.$ 20.$ 13.$ $0. 15000$ 15000.$ $ 2.87$ $.6 47.$ $00. 0.0000000000000000$ 0.0000000000000000$ $ 0.0000000000000000$ 0.0000000000000000$ $ 0.0000000000000000$ 0.0000000000000000$ $ 0.0000000000000000$ 0.0000000000000000$ $ 0.0000000000000000$ 0.0000000000000000$ $ 0.0000000000000000$ 0.0000000000000000$ $ 0.0000000000000000$ 0.0000000000000000$ $ …

Total answers: 1

Multiply found text in sed – is it possible?

Multiply found text in sed – is it possible? This is what I have: echo -e "at4nbt7nct2ndt12n" | sed -rn ‘s/(.*)t([0-9]*)$/2t111t/p’ 4 aaa 7 bbb 2 ccc 12 ddd This I want: 4 aaaa 7 bbbbbbb 2 cc 12 dddddddddddd Is this possible in sed only or I have to use some other tools? Asked …

Total answers: 1

Need help with a sed script for specific word replacements in a text file

Need help with a sed script for specific word replacements in a text file I’m trying to automate a specific text replacement task for Romanian text using sed or any other suitable Unix tool. Here are my requirements: Replace all instances of the letter â with î inside words. Words that have in their composition …

Total answers: 2

Grep Multiple Pattern located in different lines and print in the same line

Grep Multiple Pattern located in different lines and print in the same line I’m trying to find a way to grep information in the file that located in the different lines and one of the pattern is contain pattern of date and time. below is the input unwantedtext unwantedtext unwantedtext unwantedtext 8/1/2022 6:15 (1st required …

Total answers: 5

How to grep for the value of a variable inside a shell script?

How to grep for the value of a variable inside a shell script? I have 2 files: a file full of values I want to look for my source text file I wrote a short shell command to loop thru my list of values and grep against my source file. If it doesn’t find the …

Total answers: 2

looking for paragraphs that contain every pattern in a list

looking for paragraphs that contain every pattern in a list I have a list of words in a file called pattern.txt. I need to search paragraphs of an input stream that contain ALL the patterns in the list. For a single pattern (foo) in paragraph I normally use the sed code: sed ‘/./{H;$!d;}; x;/foo/!d’ But …

Total answers: 1

how to print blocks of lines below a matched pattern using sed

how to print blocks of lines below a matched pattern using sed I have a logfile to which I regularly append new blocks of text with first line as a tag. All tags start with +. There are no terminating patterns in the blocks. Each block can be 1 or multiple lines. +numbers 23 -87 …

Total answers: 3

How to make bash not assign a n to a variable?

How to make bash not assign a n to a variable? I have a variable that goes more or less like this: $ echo "$LIST" file1: ok file2: ok file3: file4: file5: ok Then I need to get the list of files that are not ok: $ sed ‘/:s.+$/d’ <<< "$LIST" file3: file4: That works …

Total answers: 3

Using the SED command with special characters

Using the SED command with special characters Is there a way to use the sed command this to search for a special character at the beginning of line, replace it with another special character, and append a special character to that line only? I did some digging and and have looked thru a few forums, …

Total answers: 1

Replace Values in a String in an Output File with a String from a Source File

Replace Values in a String in an Output File with a String from a Source File I need to replace the values, specifically the values between the equals sign ‘=‘ and the colon ‘:‘ in an existing file called zoo.cfg, at the bottom of this file i.e., … Server.1=10.42.227.70:2891:3881 Server.2=10.42.229.63:2891:3881 Server.3=10.42.234.18:2891:3881 … With values from …

Total answers: 1

Need to Extract String from Result of awk Command and Copy to Output File

Need to Extract String from Result of awk Command and Copy to Output File I want to extract strings from a terraform.tfstate file. I am running the following ack command: … awk ‘/nifi1a/{x=1}x&&/private_ip/{print;exit}’ terraform.tfstate Running this command results in: "private_ip": "10.42.229.45", I would like to extract the string between the second set of double quotes …

Total answers: 2

Need help in sed command

Need help in sed command I have the input bmb/eng/case.bmb and the output should be like: bmb/case.bmb bmx/eng/case.bmx The command i am using here is $ echo bmb/eng/case.bmb | sed -E ‘s/.*/& &/;:a;s/([^ ]* [^n]*)(bm)b/12x/;ta;s~/~&eng&~2’ bmb/eng/eng/case.bmb bmx/eng/case.bmx I have tied modifying the above command in multiple ways but i am not getting the expected output. …

Total answers: 2