Tagged Questions
3
votes
3answers
75 views
sed + how to remove character/s that start or ended on each number
How do I remove the . character(s) that start in the beginning of each number or end on each number?
Remark – perl one liner also good alternative for sed.
Example input:
.23.12.44.5.
.233.3.3.3
...
3
votes
3answers
67 views
checking data in columns when a data or some may be missing or present?
I am not sure if this possible.
say i have columns like :
Team Colour Game Rainfall PlayerName
XYZ Blue Cricket Yes Kapil
suppose i need to search ...
4
votes
3answers
80 views
Why is sed giving me an error about an unterminated `s'?
I have a set of sed replacements in a bash script and am getting an error about an unterminated `s' command. Here's what the sed line looks like:
sed -n -e "s/TMPFOO1/$FOO1/" -e "s/TMPFOO2/$FOO2/" ...
2
votes
3answers
121 views
How can I use SED or AWK to replace placeholders in a template file with variable content that contains special characters?
CentOS 6.3
I'm trying to get a small script to send an email containing a copy of email headers in the body (for the purpose of internal reporting).
The template file contains the following:
...
0
votes
1answer
97 views
comparing lines with awk vs while read line
I have two files one with 17k lines and another one with 4k lines. I wanted to compare position 115 to position 125 with each line in the second file and if there is a match, write the entire line ...
1
vote
2answers
123 views
Unix command for pattern matching
I want to count the number of words and print the matched pattern lines which matches exactly with following pattern:
abc-ERROR:
The input File contains:
# abc-ERROR: xyxxkkfgfr
# def-Error: ...
4
votes
4answers
103 views
How to remove character and space from a string
Hello I have one file with output
Name : ABC
Name : CDE
Name : ZYS
I want to get the result
ABC
CDE
ZYS
How can i get it through SED command.
I have tried. sed s/'Name' but ...
9
votes
3answers
294 views
Deleting all C comments with sed
I am trying to write a script that will delete all comments and everything in between inside C files in my current directory. I've been using sed, and this is what I have so far:
sed -i '/ * [^()] ...
0
votes
2answers
32 views
How to delete lines where the given part of the line is more than 100 chars?
I know I can delete lines that are longer than 100 chars with this:
sed '/^.\{100\}..*/d'
But I have the following example line:
<a ...
2
votes
2answers
83 views
add “#” in begining to selected lines in File
Requirement : ADD someting (i.e #) in begining of every line in file A which is grep from file B
File A
abcd
abdc
sdfg
asdfa
jon
ram
File B
jon
abcd
grep file B from file A and add "#" ...
1
vote
2answers
85 views
Regex and piped commands with sed
I'm finding really hard to use sed command, plus I can't seem to find well written tutorials.
Let me say that I worked with regular expression in other languages (Python, JavaScript, Java), so that ...
3
votes
1answer
42 views
How to edit files in-place while performing operation on the values matching the searched pattern?
Given a list files containing random text and many datetimes in ISO format in it (e.g "2012-07-02T10:47:24+02:00"), how can I find all these datetimes and add 2 hours to each one ?
Ideally a solution ...
1
vote
2answers
65 views
Match ids and print original file
I have two files
Original: (5000 entries)
Chr Position
chr1 879108
chr1 881918
chr1 896874
…
and a file with allele frequencies (2000 entries)
Chr Position MAF
chr1 881918 0.007
...
2
votes
2answers
287 views
How can I replace text after a specific word using sed?
I have a file named .ignore. In need to replace the projdir. For example:
ignore \..*
ignore README
projdir Snake
I need to replace Snake with, for example, "PacMan". I read the man page, but I ...
2
votes
6answers
164 views
Is there a faster way to remove a line (given a line number) from a file?
A related question is here.
I often have to edit a large file by removing a few lines from the middle of it. I know which lines I wish to remove and I typically do the following:
sed ...
2
votes
1answer
44 views
extracting and copying parts of tex files into new tex files
I have a bunch of tex files in different folders on my system. The goal is to create new tex files (using a template, that has the title page, packages, new commands,...) that combines all the ...
2
votes
4answers
92 views
How do I correct both too many and too few space characters?
I have files that are edited by people other than me. They contain lines that look like this:
<E> This is text </E>
I use some Bash shell scripts do a bunch of text replacement ...
1
vote
2answers
84 views
Print fields from file only if line starts with a specific word
I have the following file:
…
LINK=dummy 172.17.100 => 10.218.11 [PATH=/etc]
FILE=hosts 172.17.100 => 10.218.11 [PATH=/etc]
FILE=network 172.17.100 => 10.218.11 ...
4
votes
4answers
760 views
Text between two tags
I wanna retrieve whatever is between these two tags – <tr> </tr> – from an html doc.
Now I don't have any specific html requirements that would warrant for an html parser. I just plain ...
4
votes
3answers
290 views
How to remove all white spaces just between brackets [] using bash? [duplicate]
Replace text between brackets
Input
testing on Linux [Remove white space] testing on Linux
Output
testing on Linux [Removewhitespace] testing on Linux
So, how can we just remove all the ...
2
votes
2answers
59 views
sort a file based on length of the column/row
I need to sort a file based on the number of chars in the first column.
I have no idea on how to go about this. (On Linux, so sed/awk/sort is available).
An example:
.abs is bla bla 12
.abc is bla ...
1
vote
2answers
276 views
Help inserting a new line of text after matching a line of text (sed)?
I need to insert a hidden HTML input tag into any form tag within a bunch of HTML files. I assume this is possible with sed, but need help forming the command.
My idea is to search for any instance ...
3
votes
4answers
957 views
removing the first and the last character of every line from command line
I am trying to remove the first and the last characters of everyline in a text file and save the resulting truncated version in a new file. Does anyone have an idea about how to do that efficiently ...
3
votes
2answers
628 views
sed: multi-line replace of config block
I have some configuration files that basically look like
(...content...)
# BEGIN DYNAMIC BLOCK - DO NOT EDIT MANUALLY
(... more content ...)
# END DYNAMIC BLOCK
(... even more content ...)
Now, in ...
8
votes
4answers
400 views
How do I write a sed one-liner to add a character after every third character?
So, I have a string that looks like this:
AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA
And I want to split the string into 3-character chunks delimited by a '+' sign.
...
1
vote
3answers
178 views
Script matching literal pattern over multiple lines?
I have a multi-line string in the variable $PAT. $PAT must be searched for within the file $FILE. If $PAT is in $FILE, it needs to print the file with $PAT removed. If $PAT is not found, then print ...
7
votes
10answers
509 views
What's a good way to filter a text file to remove empty lines?
I have a .csv file (on a mac) that has a bunch of empty lines, e.g.:
"1", "2", "lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum ...
1
vote
2answers
223 views
Deleting specific lines and duplicates from a 11gb wordlist text file
I have an 11gb wordlist file which is already sorted as each word is on its own line.
I need to remove duplicates and lines starting from 077.
I guess I need to run sed and sort -u together but I ...
1
vote
4answers
939 views
How to print all lines after a match up to the end of the file?
Input file1 is:
dog 123 4335
cat 13123 23424
deer 2131 213132
bear 2313 21313
I give the match the pattern from in other file ( like dog 123 4335 from file2).
I match the pattern of the line ...
3
votes
2answers
142 views
Extract lines containing PAT1 but not PAT2 with sed
I want to extract the lines containing PAT1 but not PAT2 from a file. For example, with PAT1='dog', PAT2='cat', and the following input:
1 cat chicken
2 bird dog apple
3 dog orange cat
4 cat juice ...
0
votes
2answers
159 views
Easiest way to find/replace in a file using a list?
I have a file, foo.txt, and a regexp I want to find in that file. Each time I find the regexp, I want to take a line from another file, bar.txt, and substitute it in for the regexp match I found in ...
0
votes
1answer
259 views
Remove a block of lines between two patterns [duplicate]
Possible Duplicate:
Show only text between 2 matching pattern
In a bash script using sed how can I remove a block of lines beginning with -pattern a- and ending with -pattern b- where the ...
3
votes
3answers
187 views
Delete a block of lines with a condition on the last line
I have a log-file where at the end of a series of lines you can see if this block is relevant.
Now I'm looking for a command like sed to delete de blocks ending with "Content-Length: 0" and beginning ...
5
votes
2answers
319 views
Replacing missing value blank space with zero
I have input.txt tab-delimited text file around 30K lines, I would like to check each row (s1..s30K lines) for missing value (i.e blank space) and fill the missing value with zero value.See out.txt
...
1
vote
4answers
336 views
Replace text between brackets
I'm using awk '{ gsub(/BAR|WIBBLE/, "FOO"); print }' to replace text in data like:
SOMETHING [BAR, WIBBLE]
SOMETHING [BAR]
This gives the desired result of:
SOMETHING [FOO, FOO]
SOMETHING [FOO]
...
9
votes
4answers
1k views
Delete last line from the file
I use sed to quickly delete lines with specific position as
sed '1d'
sed '5d'
But, what if I want to delete the last line of the file and I don't know the count of lines (I know I can get that ...
4
votes
3answers
249 views
Delete the matching line and several more from a file
I have a text file called file_a.txt.
My first command is
grep -A 12 ".production =" file_a.txt
The output is a few block.
Each block of string contains 13 rows
I specifically want to delete all ...
1
vote
2answers
160 views
Substitute pattern within a file with the content of other file
I have a text file (devel.xml).
I added the word REPLACETHIS to it in order to replace this string with the content within a different file (temp.txt).
The closest thing I have is this:
sed -i -e ...
2
votes
3answers
1k views
Extracting column from comma separated text
I have a long comma-separated delimited file with 20K lines. Here's a sample:
"","id","number1","number2","number3","number4","number5","number6","number7"
...
7
votes
5answers
2k views
Remove comma between the quotes only in a comma delimited file
I have a input file delimited with commas (,). There are some fields enclosed in double quotes that are having a comma in them. Here is the sample row
123,"ABC, DEV 23",345,534.202,NAME
I need to ...
2
votes
2answers
562 views
Replace the shortest match of a string pattern
I have this string:
update mytable set mycol=myvalue where mycol=yourvalue;
I need to convert it to:
insert into mytemp select * from mytable where mycol=youvalue;
I can accomplish it like this ...
2
votes
1answer
223 views
Using sed, how can I replace a line containing a pattern with contents from another file?
input_file.txt:
one fffds
two xxxx
three ffff
four ffde
data_file.txt:
six
seven
I want to replace the line containing two xxxx in input_file.txt with the content of data_file.txt. The output ...
3
votes
4answers
2k views
How to get all lines between first and last occurrences of patterns?
How can I trim a file (well input stream) so that I only get the lines ranging from the first occurrence of pattern foo to the last occurrence of pattern bar?
For instance consider the following ...
5
votes
7answers
251 views
Swapping an unlimited number of columns
I have a file with columns. See below for an example:
a b c ... z
1 2 3 ... 26
I'd like to swap all columns where the 1st becomes the last, the second becomes the one before last...etc..
z y x ...
3
votes
2answers
100 views
Column mismatch and substituting
input.txt (tab-delimted)
TTTTOTTT00000000008 RTTTT899 5.00E-28
TTTTOTTT00000000046 RTTTWRR 3.00E-31
TTTTOTTT00000000051 2.00E-11
TTTTOTTT00000000051 7.00E-12
TTTTOTTT00000000054 ...
2
votes
1answer
950 views
Delete last character in a word but only if the character is there - in bash
How to remove last character only if it's there?
input:
OpenOffice.org/m
openOffice.org/ozm
Pers.
Pfg.
phil.
Prof.
resp.
Roonstr./m
roonstr./ozm
desired output:
OpenOffice.org
openOffice.org
...
2
votes
2answers
133 views
How to Wrap a file with Tags in Bash
I have an xml file named test.xml, without a root tag like this:
<cat></cat>
<name></name>
<id></id>
<cat></cat>
<name></name>
...
2
votes
2answers
249 views
remove only specific text occurrences from string using sed
I have a text file that contains many rows of this sort of thing:
/*[17:51:27][1 ms]*/ UPDATE `country` SET `region_id` = '4' WHERE `country_id` = '36';
Is there a way that I can use sed to remove ...
2
votes
1answer
188 views
Duplicate selected words with sed and replace it
I have to modify a document containing xml data; one modification I couldn't set up with sed.
I have to modify the following expressions from:
<Bild ...
4
votes
2answers
599 views
delete first line of file only if blank using sed
I have a solution for this in awk:
awk '{if (NR==1 && NF==0) next};1' somefile
but was unable to find one that worked in sed. E.g.,
sed -i.bak '/^$/{1,1d;}' somefile
ended up deleting ...


