Ubuntu :: Replace All Tab Stops In A Text File With 4 Spaces?
May 18, 2011How can I make vi and nano such that when I press the tab key, it automatically replaces the tab with 4 spaces?
View 5 RepliesHow can I make vi and nano such that when I press the tab key, it automatically replaces the tab with 4 spaces?
View 5 RepliesI 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 RelatedI 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"
How could I replace text in one file with text from another file using sed?
The text in each of the files would be surrounded by a starting and ending delimiter or a starting tag, say like /* */ so to easily find them.
I have an odd request, lets say I have a text file like this:
Quote:
Code:
__##___##___IIIIII
__##___##_____II__
__##___##_____II__
__#######_____II__
__##___##_____II__
__##___##_____II__
__##___##___IIIIII
I want a script that will replace all of the hash tabs with random characters.I found this command will generate a random character
Quote:
apg -a1 -n1 -m1 -x1 -d
how to script a search and replace using that random character upon each successive find until the end of file occurs.
I'm having problems with Tomboy. I have a few hundred note files and I need to go through all of them and replace all instances of "<link:broken>a</link:broken>" with "a". Is there a bash command I can use to do this?
View 2 Replies View RelatedI have an SQL dump, file.sql that has many references to a particular domain, d1.com. I would like to run a command that can replace every occurrence of d1.com with d2.com. I've tried looking into sed before but the man pages are quite daunting.
View 14 Replies View RelatedIs 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.
I have large text files with space delimited strings (2-5). The strings can contain "'" or "-". I'd like to replace say the second space with a pipe. What's the best way to go?
Using sed I was thinking of this:
sed -r 's/(^[a-z'-]+ [a-z'-]+) /1|/' filename.txt
on creating a new perl script which replace IP address from the text file. eg. If in a file, we found any word like 11.222.333.44 then it has to be replaced to XX.XXX.333.44
View 8 Replies View RelatedCode:
#!/bin/bash
VARR=`cat /proc/asound/cards | grep HDMI | cut -c 1-2`
VARX="defaults.ctl.card $VARR"
VARY="defaults.pcm.card $VARR"
FILE1="alsa"
FILE2="alsa.new"
echo $VARX
echo $VARY
sed "s/defaults.ctl.card*/'$VARX'/g" $FILE1 > $FILE2
This is what I have right now. Well, I thought I knew sed, and apparently I don't... I tried writing this for someone else, and this has given me trouble, so since the user pretty much figured it out on his own, here it goes.
Say VARR=1, so VARX and VARY contain the above text, appended by 1.
What I am trying to do is replace the text "defaults.ctl.card 0" by VARX and "defaults.pcm.card 0" by VARY. The contents of FILE1 is the file being used to search for both text fields, and FILE2 is the output file. I tried using single quotes, double quotes, and a mixture of both, and no go whatsoever. So my question... What is the proper way of searching for text within a file and replacing with a variable?
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 RelatedI opened a text file and read some stuff. Then I (think) I closed it. Then I tried to open another one and it stopped working. It seemed to compile fine though. Why would this be?
Code:
#include <iostream>// Libraries included
#include <string>
#include <fstream>
#include <sstream>
#include <list>
[Code]....
Is there any way to use sed to replace certain text in a file with the persons username automatically? Right now i'm using
Code: Select allsed -i.bak s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g file.foo
I would like it to automatically inject the persons usrname in the replacement string. Is this possible? I've been looking on line at various sed tutorials and I cant quite find what i'm looking for. I also didn't really see anything in the forums search function.Essentially i'm trying to take this file URL...Android.rules and replace all instances of username with the persons actual username automatically.
Code: Select allsed -i.bak s/username/$USER/g 51_Android.rules
Suppose I have a pair of files containing lists. The first file is called contigs.txt and it contains a list that looks like this:
Code:
Contig822
Contig826
[code]...
As indicated in the subject, I want to search a text. If the text is present I want to replace it. But if the text is not present, I want to insert it after first line and before last line.
Searched text is:CleanCache "*";
Where * can be anything.
Example: CleanCache "false"; -> CleanCache "true";
If CleanCache "false"; is not present, only insert CleanCache "true"; after first line and before last line.
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/'' {} ;
I want to use SED to do the following: In a text file replace any occurrences of the three character string ZZZ with a quotation mark "and. replace all occurrences of a comma with a semi-colon. It is the S/ / / command which is stumping me on the first issue...inparticular how to get the replace string to be quote.
View 9 Replies View RelatedSomething very handy to do in a Linux shell, is manipulating files and strings - essentially parsing data. Write a utility which will scan in a text file and search and replace strings. We also want to keep track of how many strings we've replaced.
I know that my command would look like this: <utility name> <filename> <stringToSearchFor> <stringToReplaceWith>
Code: #!/bin/bash
[code]....
How to make mcedit not replace tabs with 8 spaces?
View 2 Replies View RelatedDoes 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
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 exists.how 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 RelatedI have a line in a text file that has 40 random characters within a tag and i want to change the characters to a new set of 40 random characters (alphanumeric a-z 0-9 etc)
The line in the text file looks like this:
Quote:
How would i go about doing that?
Also second question same as the above but how would i remove them instead of replacing them?
If I have a word in a text file and I need to replace it by another word (for example, i need to replace abc by fff) so what is the command I can type it?
I am using vi editor.
I have a big text file (350mb) and i need to replace some strings in it.
The VIM is too slow. Also I don't need to open file and view its contents. I just need to give the command to replace it for faster processing.
Which software would be the best for this purpose?
im trying to output a list of running processes via a shell script. At the moment i got this which outputs the processes to a text file called out.
echo $(ps aux) >>out
The problem is though, the processes are all just one big block of text which makes it hard to read. Does anyone know how to sort the output to a text file so that it prints to the text file at 1 process per line? I know its probably simple but im very new to linux.
Iam reading a file using C-sh script after manipulating the variables I need to dump into a new file. This in working fine but I couldn't retain the multiple spaces and tabs in a same line. For readability I want to print it back as I read. Now script treating multiple tabs as onl tab or space.
View 3 Replies View Relatedi am trying to make a script in which i can drag a file (with spaces in file name ) and it will scp the file to another computermy code is
Code:
echo "--------------------------------------------"
echo "drag file now"
[code]....
i'm trying to script a lil piece to execute in terminal so when i type something like:
scriptname textfile
the script searches the text file, replaces charecters of my choosing with charecters of my choosing
"sed" im told is the way to go, and i got summat like this going
Code:
#!/bin.sh
bash -c "sed -i.backup -e /s/char/newchar/"
(if need be, i think i can just add another line of "-e /s/char/newchar/" if i need to target more charecters or words as needed.) the issue with the above code. . . how do i get it to target whatever text file follows the command? without having to manually designate sed to it each time? e.g. in commanding:
scriptname textfile
how do i get the script to target textfile^^^?
I have a many directories each with about 20 html files inside. All the files have .html ext. What I'm hoping is possible is from command line to find some text in each one and replace it with some other text.
Basically what I want to replace is;
/awstats/
with
awstats/
I can do this easily with dreamweaver or some other application but because I have 960 pages total to do I'm hoping to do it this way.