Programming :: Sed - Replace All Spaces At Beginning Of Line With The Number 1?

Jun 21, 2010

Does any one know what syntax i could use to allow me to replace all instances at the beginning of a line with ones.

Before :

Code:
----------------------------------------------------------------------
Logical device information
----------------------------------------------------------------------
Logical device number 0
Logical device name : RAID1Mirror
RAID level : 1
Status of logical device : Optimal

After

Code:
----------------------------------------------------------------------
Logical device information
----------------------------------------------------------------------
Logical device number 0
111Logical device name : RAID1Mirror
1111RAID level : 1
11111Status of logical device : Optimal

View 12 Replies


ADVERTISEMENT

Programming :: Perl - Delete Line From Text File With Duplicate Match At Beginning Of Line

Apr 1, 2009

Was wondering if any perl guru's could help me with a quick log file adjustment. I have a text file that looks like so (tabs and newlines are revealed so you can see what separates the data):

There are maybe 100 lines of text in this file at any given time. I need to delete all duplicate lines only looking at the first bit of text prior to the first tab. It doesn't matter which one gets deleted as long as there are no two lines that begin with that same text at the beginning before the first tab. So in this example, either the fist line "1234" or the last line "1234" would need to be deleted. I already have code in my script that opens the files - I just need the code to read the text into an array and the part that would find matches based on the above criteria, and make the deletions.

If it would be easier, I can even do a system call and use SED (v4.1.5) and/or AWK (3.1.5) instead.

View 7 Replies View Related

Programming :: Replace Spaces With Underscores In File Names?

Jan 11, 2011

I often get files with many spaces as part of their names. I would like to automatically replace these spaces with underscores, but otherwise not change the file name. Is there a way to do this task with just the bash shell?

View 4 Replies View Related

General :: Sed: Replace An Unknown Number Of Patterns On The Same Line?

Jul 5, 2011

I'm trying to use sed to search for a certain 'primary' pattern that may exist on several lines, with each primary pattern followed by an --unknown-- number of 'secondary' patterns.The lines containing the pattern start with: test(header_name)On that same line is an arbitrary number of strings that come after it.I want to move those strings over to their own lines so that they each are preceded by their own test(header_name).e.g. Original file (mytest.txt):

apples
test("Type1", "hat", "cat", "dog", "house");
bananas

[code]....

View 2 Replies View Related

Programming :: Rename File Names : Replace Dots By Spaces, Keep The Extension?

Mar 28, 2011

I am trying to rename a lot of files but need to keep the extension :

the files are films names :

a.b.c.d.***.iso

the result should be replacing "." by spaces " "

this command :

for files in *.iso ; do mv "$files" `echo "$files" | tr '.' ' '`; done

put a space also before the extension iso ??

How can I rename files from

"a.b.c.d.iso" to "a b c d.iso"

View 5 Replies View Related

Programming :: Add String On The Beginning And End Of The Line ?

Aug 3, 2010

I need to output of a script to a file with tags.

I'm trying sed and was able to put a tag on the end of the line

Code:

Output is

Quote:

What I need to have is

Quote:

I'm thinking of I redirect my first sed command to a file and then use sed again to put <group> at the beginning of the line. My problem is how to put <group> to all beginning of the string.

View 2 Replies View Related

Programming :: Function Which Removes '#' From Beginning Of Line?

Apr 16, 2010

I try to do a function which removes '#' from beginning of line. But if there is not '#' then add it on beginning of line. I try something like this, can you correct me?

Code:
awk '
!/^#/{ sub(/^[^#]*/,"#$0","'$line'")
}
/^#/{ sub(/#/,"","'$line'")
}'

View 14 Replies View Related

Programming :: Expect: Reacting On A $ At The Beginning Of A Line?

Oct 17, 2010

I am having some difficulties with an expect script. What I want is that as soon as expect sees a newline followed by a dollarsign ($), that interact is done. So I would expect something like this to work:

Code:
"
$" { interact }
However it doesn't.
This is debugging output:
Code:
expect: continuing expect
expect: does " " (spawn_id exp6) match glob pattern "#"? no

[Code]...

View 3 Replies View Related

Programming :: Pad End Of Each Line With Spaces To = 80 Chars?

Apr 14, 2011

I've searched the forums and the google looking for a means to do this and haven't found anything I can use. I have a large file that looks like this:

Code:

18000034161828M850
18000034172676M850
98 093095

[code]...

I need to add spaces at the end of each line to ensure that every line has 80 chars before the carriage return. I was thinking something like this, but it doesn't do the right thing:

Code:

cat filename | sed -e 's/$/(bunch of spaces)/' | cut -c1-80 > filename2

I'm on fedora, so I can use awk, sed, bash, ksh, etc.

View 14 Replies View Related

Programming :: Insert Line Using Sed Or Awk At Line Using Line Number As Variable

Jul 25, 2011

I want to insert a line at a particular line number using sed or awk. where line number is not fixed and is in form of variable.

I want to use variable in sed or awk command.I tried something like below, but no luck.

View 7 Replies View Related

Programming :: Sed Insert Line With Leading Spaces?

Mar 3, 2011

I'm trying to insert a line using sed that has leading spaces before the text. Sed seems to be just dropping the spaces and only inserting the text. Any ideas what I'm missing?

Code:

NAM=rb134
sed -i.bak -e "$i
host ${NAM} {" /etc/crap

Instead of inserting a line with 8 leading spaces inserts it with "host" at the beginning of the line. I tried

Code:

NAM=rb134
sed -i.bak -e "$i
^ host ${NAM} {" /etc/crap

but it put the "^" at the begging of the line.

View 6 Replies View Related

Programming :: Perl Script To Replace Line After Finding Previous Line

Feb 28, 2011

At the moment I have a flat file which is being used by a few people. I want a script to remotely change the file, so I can start logging who is doing what.At this point here is one requirement I am trying to develop. We have text blocks who pretty much look like.I hope this is somewhat clear. I try to find $param for the right $workflow and change that. Can you help me to find $$var3 and change that?

View 1 Replies View Related

Programming :: Replace String By Incrementing Number

May 30, 2011

Say I have a file as

[code]....

It would be great, if i could issue a command (Vi/Bash/awk, ...) in order to obtain

[Code]...

So, the "replace string" should be replaced by another string containing the counter of replacement.

View 7 Replies View Related

Programming :: Create File Listing In C++ That Will Generate Line Number On Every Line Of Code

Apr 11, 2010

I have a project due for my Intro to C++ class and we are suppose to generate a file listing that will take an input of a C++ source code with .cpp extension and make a copy of it with a .lst extention that will have a line number preceding each and every line.

View 12 Replies View Related

Ubuntu :: Find And Replace With Sed At Beginning Of A Word

Nov 15, 2010

I want to write a small script to rename a bunch of files. Their name is of the form 'long number'|'name'|'extension', for example:

52354Football_part2.flv
2353452Nice_weather_4_ducks.flv

I would like to rename these to:

Football_part2.flv
Nice_weather_4_ducks.flv

If in my script I use something like

Code:
sed s/[0-9]//g
on each file, I will get
Football_part.flv, instead of Football_part2.flv,
and
Nice_weather__ducks.flv, instead of Nice_weather_4_ducks.flv.

how to instruct sed to only remove numbers that are in the beginning of the name in a simple way?

View 2 Replies View Related

Programming :: Awk Multiple Line Search And Replace?

May 1, 2011

I am trying to search and replace a multi line pattern in a php file using awk.The pattern starts with

<div id="navbar">
and ends with
</div>

[code]...

View 3 Replies View Related

Programming :: Replace A Complex Line In Lvm.conf

May 19, 2011

I need to replace a line in the lvm.conf file from: filter = [ "r|/dev/.*/by-path/.*|", "r|/dev/.*/by-id/.*|", "a/.*/" ] to: filter = [ "a|/dev/cciss/c0d0.*|", "a|/dev/disk/by-id/.*|", "r|.*|" ] And I was hoping there was a way to use sed or awk to do this in a script (as I need to repeat this on several machines).

All of the examples I've found don't see to work with all of the special characters in the line that I need to replace. Then I need to add a line after the above edit like this: types = [ "device-mapper", 253 ]

View 3 Replies View Related

Programming :: How To Run Code On Certain Line Number In AWK?

May 9, 2010

I want to be able to run a piece of AWK code on a record specified by number, not by a regex.

View 6 Replies View Related

Programming :: Bash Search Line And Replace Hex To Binary?

Jul 7, 2011

I need a command to search a string in a file and then to convert the next string in the same line from hexadecimal to binary. I was able to put everything in capitals. The original file can be as such:

E 2
C 1 794
T ffff
E 2
C 1 787

It is not always FFFF! I am trying to do this in a file at once, not reading line by line (using while).

View 5 Replies View Related

Programming :: Multi-line Find - Replace With GnuWin32 Sed?

Apr 26, 2009

I would like to have a script that will do a search in an XML file for a specific block of XML code and replace it with a different block of XML code using the Windows build of GNU Sed 4.1.5.

Here's the text I want to find:

Code:

And here's what I want to replace it with:

Code:

There is however a lot of stuff in there that would mess up sed, and the one example from the sed FAQ (from the Sourceforge site) that looked promising and easy enough to figure out (4.23.3. Try to use a block of "literal strings") fails with this error message: sed: file blockrep.sed line 18: unterminated `s' command

Anyone got any ideas, or even an alternate program that can do this? (Preferably one that I can automate.)

View 4 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:

Code:

I want to replace instances like this:

Code:

with this:

Code:

Using this:

Code:

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

Watch:

Code:

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 Character With Hex Value Choosing From Shell Cmd Line?

Jun 9, 2011

I am bouncing a file across platforms (windows->solaris->mainframe), and the file is starting out with a "special" character (the registered trademark "circle R") in some of the records. This character is not in the EBCDIC character set on the MF, so it is unrecognizable. The MF developer I am working with asked if it is possible to replace the character with a specific hex value (AF) before it gets to the MF.

I was putzing around with sed, tr, etc. on the ksh command line, hoping to find an easy way to get one of them to substitute hex instead of ASCII. I have found that the usual shell utilities recognize the trademark character, so homing in on what to replace is solved. But I cannot get anything to actually substitute in the hex sequence I want. E.g. I was thinking something like...

>cat special_file | sed 's/R/AF/g'

But my version of sed does not seem to have hex "editing" capability.

View 5 Replies View Related

Programming :: Shell Script Replace A Line From A File?

Mar 4, 2010

I am beginner in this business of shell script and I have no idea how to do the following: I would like to replace the lines of my file that contains 'CFL=' by 'CFL=0.5'. Note that I want to replace the full line meaning

View 11 Replies View Related

General :: Convert String To Number Without 0 In The Beginning

Jun 8, 2010

I want to convert strings like 002, 049, 050, 100 to numbers: 2, 49, 50, 100.

I tried to use:
Code:
`printf "%5d" $i`
, but it doesnt work , it convert:
002=>2
014=>12
049=>0

View 11 Replies View Related

Programming :: Replace An "entire" Line Containing A Particular String With A New Line?

Mar 12, 2010

I think this can be done using sed. Let's say I have file called, "orig.txt" with following contents:

Code:
[User Prefs]
Ignore Unrequested Popups=1
DevTools Splitter Position=500
History View Style=0

[Code]....

So basically if a line contains the word "Home URL" then go ahead and replace that *entire* line with the supplied *new* line.

View 4 Replies View Related

Programming :: Count The Number Of Slashes In Each Line?

Jan 18, 2010

I have a file with lines that look like this:

Dev/7_Texas2004/4_Caves/page.htm
Dev/7_Texas2004/5_SanMarcos/page.htm
Dev/7_Texas2004/6_Austin/page.htm

And I'm trying to count the number of slashes in each line. I figured (with my limited knowledge of bash) that the best thing to use would be sed. So I ran this to print "not /": sed '!s////g' file # and eventually adding " | wc -m" to it. and I got the same result as if I ran cat, no modification at all:

[Code]...

View 7 Replies View Related

General :: Replace Multiple Spaces By One Tab

Feb 2, 2011

Ive some textfiles which contains some colums seperated by a various number of spaces, but instead i need one single tab as a seperator.

View 5 Replies View Related

Programming :: Bash:Printing The Line Number In Script?

Feb 4, 2011

I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened.

View 2 Replies View Related

Software :: Using Sed To Search And Replace Does Not Accept Spaces?

Feb 16, 2011

Back to the problem: I wrote a little bash script that people around here can run to search and replace strings in the current directory and all subdirectories. However, whenever there is a space in the new string (the one doing the replacing), I get this error:

Sed: -e expression #1, char 9: unterminated `s' command

My code looks like this:

Code:
find ./ -type f -not -name find_SNR.sh -exec sed -i 's/'$FIND_SNR_STR1/$FIND_SNR_STR2/'' {} ;

View 5 Replies View Related

Programming :: Adding Number And String To Each Line In Data File

Apr 10, 2010

I have a very large data file, with 3 numbers in each line, ex. 3 4 5 ; 6 7 8.I want to add two numbers (0 and 1) at the end of every line, and a string at the beginning of the line. Does anyone know a efficient way to do so?

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved