$ cat text.txt my name is Steven my age is 10 i like dogs   What command will be fitting so that echo "Kate" will replace Steven on text.txt?
1394
Replacing strings in files based on certain search criteria is a very common task. How can I    replace string foo with bar in all files in the current directory? do the same recursively for sub directories? replace only if the file name matches another string? replace only if the string is found in a certain context? replace if the string is on a certain line number? replace multiple strings with the same replacement replace multiple strings with different replacements
5891
I would like to change a file extension from *.txt to *.text. I tried using the basename command, but I'm having trouble on changing more than one file.  Here's my code:  files=`ls -1 *.txt`  for x in $files do     mv $x "`basename $files .txt`.text" done   I'm getting this error:  basename: too many arguments Try basename --help' for more information
39056
This line of code does exactly this except I want it to start at the first character not the 7th. $ echo 1234567890abcdefghijklmnopqrstuvwxy | sed 's/.\{1,7\}\(.\{0,1\}\)/\1/g'  What I'm looking for is 19gow
64994
file contains just 1 line:  aaa   when I run "cat file" it mixes to username  user /dir : cat file aaauser /dir :   What could be the problem ?  Extra Info:  perhaps this is not properly set in bashrc ? ?  PS1='\u \W : '   UPDATE:  shouldnt there be a solution other than including a newline to the file ?  Why would there be no care for the elements that can distort the command line prompt ? ( by not having a new line )
54667
I just wanted to ask whether there is any command which would work on common shells (bash, dash, kornshell)? It is supposed to check if the line variable contains any part of the path.  if [[ $line =~ "$PWD"$ ]] ;then
96904
Using the code below I add text to end of file names which are:  1.mp3 2.mp3   and should be:  1text.mp3 2text.mp3   but it changed to:  1.mp3text 2.mp3text   Code:  @ECHO ON  FOR %%A IN ("C:\Users\user123\Desktop\mp3\*.mp2") DO (     CALL :RenameFiles "%%~A" "%%~NXA" ) GOTO EOF  :RenameFiles  SET fname=%~2 SET renname=%fname=% REN "%~1" "%renname%text%" GOTO E
38442
I have two different files:  File1  /home/user1/   /home/user2/bin   /home/user1/a/b/c   File2  &lt;TEXT1&gt; &lt;TEXT2&gt;   I want to replace the &lt;TEXT1&gt; of File2 with the contents of File1 using sed. I tried this command, but not getting proper output:  cat File2|sed "s/&lt;TEXT1&gt;/$(cat File1|sed 's/\//\\\//g'|sed 's/$/\\n/g'|tr -d "\n")/g"   You can use other tools also to solve this problem.
4793
I want to do:  cat update_via_sed.sh | sed 's/old_name/new_name/' &gt; new_update_via_sed.sh   in my program.  But I want to use variables, e.g.  old_run='old_name_952' new_run='old_name_953'   I have tried using them but the substitution doesn't happen (no error). I have tried:  cat update_via_sed.sh | sed 's/old_run/new_run/' cat update_via_sed.sh | sed 's/$old_run/$new_run/' cat update_via_sed.sh | sed 's/${old_run}/${new_run}/'
33101
How do I echo one or more tab characters using a bash script? When I run this code  res='       'x # res = "\t\tx" echo '['$res']' # expect [\t\tx]   I get this  res=[ x] # that is [&lt;space&gt;x]
112544
What's wrong with the commands below?  $ var1="~/Music/$(date +%d%m%y)" $ echo "$var1" ~/Music/240118 $ mkdir "$var1" mkdir: cannot create directory ‘~/Music/240118’: No such file or directory   However  $ mkdir ~/Music/240118   works.  Never thought I would ask such questions after years of using bash...
10395
I've got a bunch of files named with a the pattern 99 - DescriptiveName.txt and I'd like to remove the number from the front so I just have DescriptiveName.txt.  How can I do this? Can I do it from the command line or is there a utility that can do this?
58175
I have multiple files that contain ascii text information in the first 5-10 lines, followed by well-tabulated matrix information.  In a shell script, I want to remove these first few lines of text so that I can use the pure matrix information in another program.  How can I use bash shell commands to do this?    If it's any help, I'm using RedHat and an Ubuntu linux systems.
117282
I am trying to append and prepend text to every line in a .txt file.  I want to prepend: I am a   I want to append:  128... [}  to every line.  Inside of a.txt:  fruit, like bike, like dino, like   Upon performing the following command:  $ cat a.txt|sed 'I am a ',' 128... [}'   it does not work how I want it to. I would really want it to say the following:  I am a fruit, like 128... [} I am a bike, like 128... [} I am a dino, like 128... [}
12267
I am making the check for update script for my theme  I have 2 text files. First one is called "current.txt" and contains the current version. There is 4.1.1 string in that text file.  Second one is called "latest.txt" and contains the latest version. There is 4.2 string in this text file.  So here is the code  echo "Checking update"; x=$(cat ./current.txt) y=$(cat ./latest.txt) if [ "$x" -eq "$y" ] then        echo There is version $y update else        echo Version $x is the latest version fi   What it mean is if current.txt is NOT the same with latest.txt then it will say "there is version 4.2 update". If not, it will say "version 4.1.1 is the latest version"  But when I try to run it. I get this error  Checking update ./test.sh: line 4: [: 4.1.1: integer expression expected Version 4.1.1 is the latest version   So what am I doing wrong with this?
15664
I have a text file named links.txt which looks like this  link1 link2 link3   I want to loop through this file line by line and perform an operation on every line. I know I can do this using while loop but since I am learning, I thought to use a for loop. I actually used command substitution like this   a=$(cat links.txt)   Then used the loop like this  for i in $a; do ###something###;done   Also I can do something like this  for i in $(cat links.txt); do ###something###; done   Now my question is when I substituted the cat command output in a variable a, the new line characters between link1 link2 and link3 are removed and is replaced by spaces  echo $a   outputs  link1 link2 link3  and then I used the for loop. Is it always that a new line is replaced by space when we do a command substitution??  Regards
77608
I used one of the following  echo $(stuff) echo `stuff`   (where stuff is e.g. pwd or date or something more complicated).  Then I was told this syntax is wrong, a bad practice, non-elegant, excessive, redundant, overly complicated, a cargo cult programming, noobish, naive etc.  But the command does work, so what exactly is wrong with it?
22838
Is there any text editor, which can edit such file?  I've  tried:   gedit kate nano vim mcedit   without success.