General :: Replacing A Line With Spaces?

Jan 5, 2011

I have a line like

port = 2566

I want to replace it as

port = 8080

how to do this in shell script. when i tried to do this with sed

sed -i 's/port=.*/port='$3'/' /root/$2

it is not recognizing spaces , it works only if line is port=2566 .

View 6 Replies


ADVERTISEMENT

Programming :: Copy And Replacing Specific Line From File1 To File2 Line By Line

Mar 22, 2011

I have two files, file1.traj and file2.traj. Both these files contain identical data and the data are arranged in same format in them. The first line of both files is a comment.

At line 7843 of both files there is a cartesian coordinate X, Y and Z ( three digits ). And at line 15685 there is another three digits. The number of lines in between two cartesian coordinates are 7841. And there are few hundreds of thousands of lines in a file.

What I need to do is copy the X Y Z coordinate (three digits) from file1.traj at line 7843 and paste into file2.traj at the same line number as in file1.traj. The next line will be 15685 from file1.traj and replace at line 15685 at file2.traj. And I dont want other lines (data) in file2.traj get altered. This sequence shall be going on until the end of the file. Means copy and substitude the selected lines from file1.traj into file2.traj.

I tried to use paste command but I cant do for specified line alone.

Here i showed the data format in the file. I used the line number for clarity purpose.

Code:

View 10 Replies View Related

General :: Spaces In Command Line Switches

Oct 6, 2010

I am trying to encode files via mencoder. The file name has spaces in it. "test file.mkv". When I manually type the command in the terminal, everything works. But when I use a bash script (I'm reading it from a file) it doesn't. It gives me

Code:
File not found: '"test'
Below is the bash script I wrote

Code:
#!/bin/bash
# For testing, we have already built a file list, so just use that.
# ls *.mkv>files.lst
exec 10<files.lst
let count=0
while read -u 10 FILE; do
LINE="mencoder -of lavf -lavfopts format=mp4 -vf scale=1024:-3 -ovc x264 -x264encopts crf=28:vbv_maxrate=1500:nocabac:global_header:bframes=0 -oac faac -faacopts br=160:mpeg=4:object=2:raw -channels 2 -srate 48000 "$FILE" -o test.mp4"
echo $LINE
exec $LINE
done

exec 10>&-
files.lst contains only a single line (no newline) with
Code:
test file.mkv

On a related note, when I was first trying this simply on the command line, I had a file that had a double exclamation point. I found out that that is a shortcut of some kind for the previous command. My kludge to get around this was to try to execute a single exclamation point as a command, then to change the double exclamation point to a quadruple exclamation point. Is there a proper way (escape sequence or something) to pass double exclamation points to a command?

View 2 Replies View Related

General :: Finding And Replacing Whole Line Using Sed

Mar 19, 2011

assume that i am having the following line in a file called file1. triumph and disaster must be treated same. I want to replace this line with. follow excellence success will chase you. is it possible to do this using sed. if possible kindly post me the code.

View 6 Replies View Related

General :: Access Files With Spaces From Command Line?

Mar 17, 2011

How do I access files with spaces from the command line?
for example I want to go to a file called "New File" and let's say is in Downloads/Books/(and here is the file)
how do I input the space since the command line doesn't recognize it?

View 2 Replies View Related

General :: Shell - Rename A File From Something Without Spaces To Something Containing Spaces?

Jan 26, 2010

Is it possible, in Linux, to rename a file from something without spaces to something containing spaces? I know I can create directories and files with spaces by doing:

mkdir "new dir" and:

touch "new file.txt"

I want to rename files from:

imgp0882.jpg to something like:

20091231 1243 some topic.jpg

And how would it look in a shell script that uses parameters like:

for i in *.jpg do
rename "$i" "$somepath/$mydate $mytime $mytopic$extension"
?

I'm new to Linux (using PCLinuxOS 2009.2), coming from Windows, and I've written myself a little shell script to download files from my camera and then automatically rename them according to a date-and-topic pattern. As you can guess by now, I'm stuck on the bit about renaming. If you want to see my script, here's a copy. I'm not using jhead for this renaming because that only works with JPEG files but I want a single solution for any media format including videos.

View 2 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 :: 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 :: 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 View Related

Software :: Tool For Replacing First Match Per Line?

May 4, 2010

I've got a file that I want to convert to a CSV format.

Each line of the file is something like:

term1a term1b [pronunciation] definition
term2a term2b [pronunciation] definition
term3a term3b [pronunciation] definition

To get it into CSV, I just need to perform 3 find and replace operations:

First, replace the first " " (space) with a "," (comma). Next, replace the first " [" (space and right-facing square bracket) with a "," (comma). Finally, replace the first "] " (left-facing square bracket and a space) with a "," (comma).

The reason it must only be the first such occurance, is the definition area contains lots of spaces and square brackets which I'd like to leave left untouched.

View 1 Replies View Related

Programming :: Replacing Set Of Characters In A Specific Line Using Sed Or Awk?

Dec 29, 2010

I would like to replace 'xxxx' with 'yyyy' which is in a file xyz.csproj not sure of what 'xxxx' is, it can be 3055, 4056, 7089 etc. I know it always appears at line # 5 and at character 50.

<Reference Include="System.Management" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Windows.Forms" />

[code]....

View 14 Replies View Related

General :: Using Tilde And Spaces

May 26, 2010

I'm trying to use a tilde '~' for a filename. This works fine normally Code: rm ~/File
But when I have a file with a space in in and enclose it in quotes it takes it literally.If a word begins with an unquoted tilde character (�~�), all of the characters up to the first unquoted slash (or all characters, if there is no unquoted slash) are considered a tilde-prefix.

View 5 Replies View Related

General :: How To Kill A Process With Name Having Spaces

Dec 10, 2010

A process with name=example can be killed by killall -9 example

How to kill multiple instances of following command which contain spaces?

"valgrind --tool=lackey ./testcases/kernel/syscalls/waitpid/waitpid03"

Following command returns valgrind --tool=lackey ./testcases/kernel/syscalls/waitpid/waitpid03: No such file or directory

View 3 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

General :: Running SCP Command With Spaces?

Jan 21, 2010

I am trying to run an scp command on my linux server, this is working fine, however I changed the output folder to one which has spaces and now when run, it's coming up saying SCP ambiguous target

Here's my string:
expect -c 'spawn scp -r /var/lib/asterisk/backups/Everyday/ administrator@192.1.1.1:
/Volumes/Data1/My Backup Folder/ ; expect assword ; send "MYPASSWORD " ; interact;'

View 4 Replies View Related

General :: Convert Tabs To Spaces In Many Files?

Jul 2, 2010

I have a lot of files with tabs littered throughout, and I'd like to convert them all into spaces. I know about the expand command, but unfortunately I would have to type out every single file using it. Is there any easier way to do this on Linux?

View 2 Replies View Related

General :: Bash Command To Remove Spaces

Sep 14, 2010

I am reading the output of /proc/acpi/thermal_zone/ATF0/temperature in a program to read my CPU temp. I am using cat like the following:

Code:
#cat /proc/acpi/thermal_zone/ATF0/temperature
temperature: 49 C

I basically want to get rid of the spaces in between temperature and the actual temperature. Is there a command I can pipe the cat output to, to remove the spaces. I have seen suggestions for sed, or tr, but for some reason I cannot get them to work properly.

View 14 Replies View Related

General :: Getting Blank Spaces In Shell Script?

May 7, 2010

I did the following script:

Code:

DIR=`pwd`;for i in `find . -name GESTION -type d`;do cd $i/..;setfacl -R -m g:directores:rwx,
GESTION;echo $DIR'/'$i;cd $DIR;done

This code do the following actions:

1. Starting inside a folder, it's searching for any folder called "GESTION"

2. Every time a folder called "GESTION" is found, then the script move to its parent folder, and then it applies ACL permissions to the folder GESTION by using the command setfacl.

The problem is that the script doesn't works when there was found a folder with a blank space in its name. I mean:

/dir1/dir2/dir3/GESTION --> this works fine
/dir1/dir2/dir 3/GESTION --> this doesn't works
/dir1/dir2/dir3/2. GESTION --> this doesn't works

View 4 Replies View Related

General :: Replaces Empty Spaces By Underscore?

Mar 11, 2011

my requirement is i need to copy mail subject to a text file and create one directory from the name of subject.

my MAIL subject is like this :

Quote:

Subject:Thanks to linuxquestions.org

i copied the mail subject to a file. and now the issue is to creating a directory.

now i want to create a directory without empty spaces, insted of space replace _ in that place.

i want out put like this.

Quote:

Thanks_to_linuxquestions.org

View 5 Replies View Related

General :: Ubuntu : Delete The Extra Spaces?

Jul 28, 2010

I want to ask a question regarding the terminal in ubuntu. When i deleted some lines in the config files for example, there will be those so-called extra spaces left after deleting and i can't seem to delete those spaces and 'pull' up the lines below. So, how to delete those extra spaces?

View 13 Replies View Related

General :: Replacing Awk With Perl?

Jul 16, 2010

I want the output of this file to be in a column, not next to each ohter. I tired putting a a newline escape character in a few places, but it breaks the script. It is easy in awk, just ls -ltr | awk '{print $8 }'

casper@casper-laptop:~$ pwd
/home/casper
casper@casper-laptop:~$ ls -ltr > /tmp/outfile
casper@casper-laptop:~$ cat -n /tmp/moreawkreplace
1#!/usr/bin/perl

[Code].....

View 1 Replies View Related

General :: Remove Spaces From Many File Names Under Cygwin?

Nov 22, 2010

I'm hoping that someone can help me, I need to remove spaces (not replace with underscores) from several thousand files on a system with cygwin.
Can I do this from the shell using rename or mv somehow?

View 4 Replies View Related

General :: Selectively Remove Blank Spaces From String?

Oct 7, 2009

need all spaces between two letters or a letter and a number exchanged for an underscore, but all spaces between a letter and other characters need to remain. One example for clarity:

Input:

force -- lamin 90 [label]
active A -- generation [label]

needed Output:

force -- lamin_90 [label]
active_A -- generation [label]

I tried solving this with sed but obviously s/ /_/g does not work, nor does any s/[a-zA-z0-9] [a-zA-z0-9]/[a-zA-z0-9]_[a-zA-z0-9]/g , because you just can't do this...

View 2 Replies View Related

General :: Replacing Dot In String But Leaving Last One?

Jan 17, 2011

Possible Duplicate: replacing dot in string, but leaving last one replace the "." [dots], but leave the last one: e.g.: .txt [there could be random number of dots in the string, even zero, i just need the last one]

$ echo 'someth.ing.something.txt' | SOMEMAGIC
someth-ing-something.txt
$

View 1 Replies View Related

General :: Replacing Ownership Of Certain Files?

Jan 30, 2010

Is there any working commandline alternative to # find /some/dir -group xxx -user yyy | chown xxxxx:yyyyyThe main purpose is to replace ownership and goup of certain files in subdirectories. Or nevertheless I need to write shell script for that simple operation ?

View 5 Replies View Related

General :: Replacing Text In A File?

Jul 26, 2010

how to replace following text in the file name.cfg ?I need to replace

name:=inet.hr=>1|inet.hr=>1
with
name:=none
I am using
sed -i 's/name:=inet.hr=>1|inet.hr=>1/name:=none/g' name.cfg

View 4 Replies View Related

General :: Replacing Character / Value In Certain Column

Jun 21, 2011

I need to replace a value in a file. For example the content of data.txt file is:
1 1 23
2 1 42
3 2 52
4 2 62
5 1 77
6 1 88
7 2 99
8 1 100

Could I substitute 2 in second column with 3 using awk and or sed or other command so that the data will be change as follow?
1 1 23
2 1 42
3 3 52
4 3 62
5 1 77
6 1 88
7 3 99
8 1 100

View 3 Replies View Related

General :: Replacing Part Of Filename?

Apr 25, 2010

I have just re transcoded a bunch of avi's. to tell the new ones from the old ones I put '[xvid]' at the end of all the new avi's. but now I have deleated the old avi's I want to remove the [xvid] part of the file name. This is what I have so far

Code:
#!/bin/bash
for name in *.avi
do
newname=`echo "$name" | tr -d [xvid]`

[Code]...

View 10 Replies View Related

General :: Bash - Rename Files With Spaces Using System Shell?

Jun 8, 2011

I named a number of files with spaces in them, and I want to replace the space with "_". However, every time I write a command in the shell with the file name (eg "Spring 2011"), the shell doesn't recognize the file or directory. What can I do about this? Is there any way to use the unicode character for a space?

View 5 Replies View Related

General :: Search A String Having Spaces / Slashes / Colons In Vi Editor

Feb 2, 2010

I need to seach a string containing

the substring of 'New Request object:'

and

the substring of '/0x2ab46b1f90' in vi editor,

how do I accomplish that?

View 7 Replies View Related







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