Find a pattern starting from a specific line of file [closed] - bash

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to find a pattern starting from a specific line rather than from the beginning and then delete all the lines starting from this specific position to the point/line where the pattern was first matched.

This will delete starting from line 10 until the pattern is matched:
sed '10,/pattern/d' file > newfile

what about this:
sed -e "$lineno,/$pattern/d" $file
where
$lineno is your line number for start deleting
$pattern is your pattern
$file is your file

Related

bash shell execution [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am using
sed -s n v
Nothing works for me
The -i flag is only in GNU Sed.
cat file | tr ']' '[' > temp
mv temp file
The above should work for you.

Replace and remove characters in string, and add output as new column [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have an output from a program that I would like to process and If I pipe it to a file I get:
file/path#backup2018
file2/path/more/path/path#backup2019
file3/path#backup2017
And I want to process it so it looks like this:
file/path file.path
file2/path/more/path/path file.path.more.path.path
file3/path file.path
I have figured out how to make it with separate commands but would like a one liner.
$ awk -F# '{s=$1; gsub("/", ".", s); print $1, s}' file | column -t
file/path file.path
file2/path/more/path/path file2.path.more.path.path
file3/path file3.path
using sed
sed 's/\([^#]*\)#.*/\1 \1/g' file|column -t

How to use sed to create new txt file without specific words [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a text file that contains $string . How would I use sed to create a new txt file without all occurrences of $string ?
You can use the following sed command that will replace all the occurrences of your string variable by the the empty string '' and by redirecting the output to a new output_file.
sed "s/$string//g" input_file > output_file
or you can use the following sed command:
sed -i.bkp "s/$string//g" file
to work directly inside the file passed as parameter, -i.bkp option will create backup file automatically with an extension .bkp, (in the above example file.bkp), if no need of backup, use just -i
Last but not least, your $string variable should not contain any slash / if there are any you should escape all of them using \. You can create a function to perform this task.

Sed to edit multiple patterns [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Is there a way to change multiple (up to ten) patterns in a single fasta file using sed?
For instance I want to change X for Y:
sed "s/X/Y/g" < file1.fasta > output.fasta
how to add sed "s/\s/_/g" and 8 more commands to the same one-liner?
You can separate the commands by semicolons
sed 's/a/b/;s/c/d/'
(you can also use newlines instead of semicolons)
or you can use multiple -es:
sed -e 's/a/b/' -e 's/c/d/'
see this example: (test with gnu sed):
kent$ echo 'abcd'|sed 's/a/1/;s/b/2/;s/c/3/;s/d/4/'
1234
kent$ echo 'abcd'|sed 'y/abcd/1234/'
1234

insert the content between matching pattern in unix [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to insert the content between the matching pattern in shell please help on this
For example :
file called input.txt :
var a = [ ]
file called output.txt :
1152
1185
1185
I want to insert the values from output.txt file to the file input.txt.
it should be like var a = [1152 1185 1185]
sed "s/\[/[ $(xargs < output.txt)/" input.txt
xargs < filename dumps all file lines in just one, i.e., replaces EOL characters for SPACE characters.
$(xargs < filename) expands to the contents of the filename in just one line. Hence the use of double quotes, not single ones.

Resources