Software :: Replace Newline Pattern In File By Other Newline Pattern In A Shell Script?

Nov 22, 2010

I have several (vhdl) files containing a pattern with newline characters that I need to replace by another pattern that also contains newline characters.

I start with something like:


I want to replace it by something like:


(I need to paste some lines)

As I need to do this (very) often I want to use a shell script.

I tried:








File remains unchanged








Displays the unchanged testfile

How I can automate the pattern replacement?


View 9 Replies


Programming :: Search A File For A Particular Pattern And If Pattern Found Replace The Line With New Text?

Feb 24, 2010

I want to search a file for a particular pattern and if pattern found replace the line with new text. i am using awk 'match($0,"pattern") != 0 {print $0} ' filename to check if the pattern do i get the line number of the pattern and delete that line and replace the line with my new text?

View 1 Replies View Related

General :: Replace A Pattern In A File?

Jun 11, 2010

I want to replace a pattern in a file.The file format is given below.



I want to replace "path=/home/fun" with another pattern, but only under "111111", all the others should be the same.

View 14 Replies View Related

Programming :: Sed Command To Replace 7th Tab With Newline

Mar 11, 2011

I have a tab delimited file. I need to replace the 7th tab with a new line.

I tried the following command (but it does not work):

The above simply spits out the original file.

If I write the next command, it replaces the first tab in each line with a newline. How can I make it replace the 7th tab in each line?

View 4 Replies View Related

General :: Remove <br> Html Tag And Replace With Newline

Dec 2, 2009

I've been playing around with sed but can't find a way to remove the <br> html tag and replace it with a newline. Sed isn't truly needed awk or other suggestions could be good.

View 3 Replies View Related

Programming :: Sed To Read The File And Replace And Insert The Pattern?

Jun 11, 2009

I want to read from the file and check for the pattern, if the line has some word like <string>: then string should be copied into buffer. Afterwards, I want to insert the same <string> with some word in the next line of the file. use sed command to perform the above mentioned operations?

View 2 Replies View Related

Programming :: Search File By Pattern And Then Delete Corresponding Lines In Shell?

Sep 16, 2010

I have such a file(test.txt):

abc 123 456
abc 256 145
axd 125 225


View 8 Replies View Related

Programming :: If Statement Pattern Search / End Of Pattern Special Character?

Apr 29, 2010

I have to enhance the behaviour of a backup script written in perl. I don't need to change it, what I need to do is to create a bash script that does some checks like file name and file size, execute the backup script then check if the backup files match the original files.Here's how I try to do it:

- read the files from the original files folder
- store them in an array
- search in the array the files that have a specific file extension
- store the file names that match the search pattern (I know the backup script skips some files so I can hardcode the search pattern)
- run the backup script
- read the files from the backup folder
- store them in an array
- compare the original files name and size stored in an array with those from the backup folder
- send a report email

View 3 Replies View Related

General :: Shell Scripting: Inserting Text Into A File Name With A Predictable Pattern

Apr 18, 2011

Just using shell scripting, how can I insert text into the middle of a file name. The file has a predictable pattern, let's say 3 letters and 3 numbers and I want to insert text in the middle of those 2 patterns. Say ABC123 is the file name. As a result, the file name should be ABC.blah.123

View 2 Replies View Related

General :: Removing A Line From File Which Is Having Specific Pattern Using Shell Script?

Mar 20, 2011

I'm new to the shell scripting. can any one help in creating shell script for matching the content of the specific variable with file. it should remove that line from the file if line is containing same value as variable and keep the other content as it is.i used grep -v for accomplishing the same. But grep will remove the pattern which is similar.For eg. Assume file "test" contain datas :aaffif i used grep -v command for the pattern "a" to this file this will remove content "aa" from the file. I want the pattern only "a" should remove from the file, if it is existing. otherwise it should throw alert content not exists.

View 5 Replies View Related

General :: Add (not Replacing) A Pattern Match With A Similar Pattern?

Aug 30, 2009

I'm writing a bash script to search html files, and when I find any occurrence of an img src tag like this:

<img src="123-picture-normal.jpg" alt="some random user entered text" border="0">

I want to add a second line below it that looks like:
<img src="123-picture-thumbnail.jpg" alt="some random user entered text" border="0">

All I need to do is duplicate the line but replace "normal" with "thumbnail"

Each file can have multiple img src tags with different numbered jpgs.

I have a feeling this is a job for sed, but I'm struggling with it. Any ideas?

View 2 Replies View Related

General :: Shell Script To Delete File If A Pattern Is Found And Restart Servers?

Jul 22, 2010

I have requirement to delete some log files from a directory if a string"deletethisfile" is found.Then restart the application servers.1. Search for the string ?deletethisfile? in server.log file under a directory, If found 2. Stop that particular server.3. Delete the log file 4. Restart the server.

View 2 Replies View Related

General :: Find Pattern After Specific Pattern

Oct 11, 2010

I want to go through a log file and find pattern1 and then a pattern2 only after pattern 1.So for example I want to know howManyRecords was in 13:30.I figured I grep for "start time for the job" and then only after that (and before the next occurence of that) grep for "howManyRecords". Is this a sane way?

View 1 Replies View Related

Software :: Extra Newline At End Of File?

Apr 11, 2009

I've noticed when I create a generic textfile in vim and have a trailing newline at the end of the file, when I open it with kate it has 2 new lines at the end of the file instead! This is on a fedora machine. The same behavior is observed when I copy the file over to my windows machine and open it in notepad++ (which is able to handle both unix and dos newlines) - 2 newlines instead of 1.

Feeling curious, I tried creating a textfile in vim on my ubuntu machine and used gedit to open it, but surprisingly gedit displayed it correctly - only 1 newline.

View 7 Replies View Related

Programming :: S/ Command Won't Replace Two Occurrences Of Pattern On Same Line

Dec 15, 2009

Here's the actual line of code, which exists in a bash script:


I want to replace instances like this:


with this:


Using this:


Which works great when there's only ONE of the pattern on the line. But in a case like the "actual line" I posted first, where there are two patterns, separated by a slash, only ONE gets replaced



Why? There must be (among many other things) something I'm not knowing about sed, that's causing this.

-- I'm currently using the ~ (tilde) as the separator in the sed command. It doesn't matter, I've used / ~ and % with no difference.

-- As a test, I tried putting a different character(s) in the middle of the original pattern instead of the / but that made no difference.

-- I've come up with various similar but slightly different regexs that will do this replacement, but they all have had this same result.

-- I tried the sed single-quoted, double-quoted, and unquoted; the latter fails to execute, and the formers both work as described here: wrong.

View 7 Replies View Related

Programming :: Replace Pattern In Specific Lines And Column With AWK?

Apr 24, 2010

Im tryng to replace in specific column and line number within a file where its 3erd column contain the same string in all lines.


My goal is to replace only first and last ocurrences of "Normal player", with the following desired output:


Im not sure how to use the "IF" and "AND" conditions together. I�ve tryed with the code below, but the script replaces the string for every line.


how to replace values for specific column in first and last lines within same AWK script, without taking reference data in other columns?

View 10 Replies View Related

Ubuntu Installation :: Update Error - Files List File For Package `libxcb-shape0' Is Missing Final Newline

Feb 23, 2010

I have recently taken delivery of a Dell Inspiron mini netbook with Ubuntu on, and I am new-fangled .install updates, I clicked the (orange down-arrow) button, and it compalined "E: /var/cache/apt/archives/linux-image-2.6.24-22-lpia_2.6.24-22.45netbook9_lpia.deb: files list file for package `libxcb-shape0' is missing final newline"

View 2 Replies View Related

General :: Shell Script To Extract Single Report By Pattern Then Both Backward And Forward

Feb 18, 2010

I have to admit that I register to LQ after I failed to search for similar solutions.let me see whether I can explain my problem clearly. I need to extract a single report from a big file. The big file looks something like this:

Report for yyyyyy
Your info 999-9999999
End of Report


I need to search for a user provided string, say 999-9999999, in the big file. Then I have to extract the single report. My logic is simple,

1) find 999-9999999
2) backward search for "Report for", note down the line number
3) forward search for "End of Report", note down the line number
4) extract the record by using info found from step 2) and 3).

I am trying to do this in bash, with awk and sed (I am new to both).

View 8 Replies View Related

Programming :: Shell Script To Delete Part Text Of A Line If Pattern Matches?

Apr 12, 2010

I am trying to create a shell script, on taking a input file as parameter, which need to do 3 things

1) create a copy of existing file.

2) add a new line to the copied file.

3) strip off all the absolute paths inside the copied file

The first 2 points are straight forward. but i am finding it difficult to acheive the 3rd point. myself not very good with awk and sed. but gave it a shot in vain. For example, the input script consists of below,

PROGRAM=`/usr/bin/basename $0`
HOST=`/usr/bin/uname -n`
echo Start $PROGRAM `/usr/bin/date` |
/usr/bin/tee -a $LOG

The output of the script should look like,

PROGRAM=`basename $0`
HOST=`uname -n`
echo Start $PROGRAM `date` |
tee -a $LOG

View 14 Replies View Related

General :: Sed Scripting "replace Value For Only Last Part Of A Pattern "?

Apr 26, 2010

All i want is to replace some part of$1=" alok 10"i want to change 10 with any number/string so that result comes as "alok 20". Is itpossible with sed ?I am looking for code some thing related as :echo "alok 10" |sed -ie "s/$1/$1 10/g I know the above is wrong , its just for your reference. Also, while replying kindly explain wherever is required.

View 3 Replies View Related

General :: Where Did The Trailing Newline Characters Go

Aug 11, 2011

I am working with bash scripting and running into a weird issue where the trailing newline characters are being truncated.The file contents are something like:

# Catting the file shows the trailing
cat /tmp/junk
first line
second line


Since I am working with config files, some of the applications/daemons fail to start if they fail to find trailing newline characters

View 4 Replies View Related

Programming :: Prevent Sed From Replacing With Newline

Nov 28, 2009

I'm writing a script to replace some text that exists in about 50 .lex, .y, and .cc source code files, sometimes more than once in a file. Sometimes the text is in a multiline C comment, and other times it's within a multiline C string.

I use sed to grab the start and end of each line and wrap the new text in the old whitespace and/or quotes and Problem is, sed is changing the characters into a newline.

Is there a way to tell sed to not process escape sequences? I tried using several variations of


To no avail. Or could it be bash?

I would give up on the script and do it by hand, but this is something that I must do from time to time.

Here's the function which replaces the first occurrence found:


When $post is printed by echo, it shows the - but by the time the file is on disk, it becomes a newline. What should I do to ensure that it stays as the characters ?

View 4 Replies View Related

Programming :: Using An Alias Or Function Without The Newline?

May 1, 2010

I want to create an alias or function that when used prints something like this on the command line so I can further modify it before pressing enter myself.

$ FILE=exercise1; cc -o $FILE $FILE.c && ./$FILE; FILE=
The idea is that I'm studying c and want to change the name of the file once instead of


View 3 Replies View Related

Debian :: Create File With Repeating Pattern?

Jul 22, 2010

I want to create some files of a specific size containing a repeating pattern. I did some research and found that I can create a file and fill it with (fairly) random data by using dd like so: dd if=/dev/urandom of=myfile.dat bs=$(( 1024 * 1024 )) count=100 (Creates a 100 MB file.) I found that here: Quickly creating large files.

Rather than fill a file with random data, I'd like to use these patterns: 0xaa, 0x55, 0xff, and 0x00 (one per file). Is there a simple way to accomplish this?

View 8 Replies View Related

General :: Using Grep With Pattern File And PCRE

Sep 25, 2010

I would like to write a newline delimeted rules file using PCREs for use with the grep command. Grep has the option -f to obtain the search pattern from a file, and option -P to search using PCREs. However, these two options do not work together. The -f option only seems to work with fixed string rules.A friend previously helped me get around this limitation somehow, but I can't remember how he did it. I also would like the ability to add comments at the end of each rule in the file.

View 11 Replies View Related

Programming :: Sed -n '/pattern/{n;p;}' Is Missing Matches In File?

Jun 16, 2011

I have an interesting problem, sed '/pattern/{n;p;}' file, doesn't seem to be catching all of the matches in my file. As an example of this see below.test:



View 5 Replies View Related

Debian :: Append File Content In Another File When Pattern Matches

Feb 5, 2010

I have a file, say abc.txt, whit some text lines.The I have a second file, say 123.txt where at a certain point one can read "WORD".I would like to append the whole content of abc.txt (as it appears in abc.txt) in the line after "WORD".

View 1 Replies View Related

General :: Concatenating 2 Files Without Creating Newline Between Them?

Dec 23, 2010

Concatenating two files without creating a newline between them? So how is it possible to do that? I've tried the following:
echo 123 > file1
echo 456 > file2
cat file2 file2 > file3


View 8 Replies View Related

Programming :: Inserting Multiple Lines - With Newline - Using Sed Or Awk

Mar 8, 2009

I need to replace part of a line in a file with multiple lines, however need to separate each line with a newline is this possible?

Example, need to remove line 2

And insert line similar to below:

If the multiple lines were part of a text file, would inserting a text file automatically include newline characters?

View 1 Replies View Related

General :: File Matching Pattern On Command Line?

Sep 9, 2011

I've got files in a directory as follows:



I want to list all the files that don't have a copy with the same filename with -1 somewhere in it. So, in the example above, the results would be 3.png.

NB: the file and its copy with "-1" in it will be the same filesize, if that helps.

View 2 Replies View Related

Copyrights 2005-15, All rights reserved