Jump to content
  • Bash replace line in file

    txt a. This script will take the filename from the command line argument. To perform a replace on a line which ends with ‘two’. Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. format that contains text) in a very short time. Reading the file; Finding and replacing the string; Writing changes to the file. {3}). sed '/^$/d;G' # triple space a file sed 'G;G' 2 # substitute (find and replace) "foo" with "bar" on each line sed ' 25 Jun 2017 Here our requirement is to replace a line with our content when a match is found with in the file Our sample file /tmp/file This is line one This is line two. The ‘awk’ command can also be used to replace the I want to replace this line in a conf file with my own line: Replace this line: #maxmemory <bytes> with: maxmemory 26gb. will replace the content by adding the '$' symbol at the beginning of the numbers. srk: Linux - Newbie: 5: 02-26-2010 06:00 AM: how to replace line of file with another line using awk in shell script: amit_pansuria: Programming: 3: 03-29-2009 09:43 AM: How to identify a line and replace another string on that line using Shell script? Sid2007: Programming: 10: 10-01 While loop in bash using variable from txt file. Brief: This example will help you to read a file in a bash script. txt Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Learn bash in y minutes (learnxinyminutes. Forums. By the end of the post, I’ll show you a function I built to make your life much easier. The characters CRLF are often used to represent the carriage return and linefeed sequence that ends lines on Windows text files. Jul 24, 2020 · Suppose if there are multiple instances of ‘two’ in the file but you would like to perform replacement only on the line which starts with ‘two’. Nov 02, 2018 · Shell Script to Read File. Our file name was sed. Inline replacement of all newlines in file with br tag If you have GNU sed, you can use the -i option, which will do the replacement in place. Command: sed '2,3 s/sed/sed replace/' input_file. # sed ‘/three/ c your text’ /tmp/file. I get the error: sed: -e expression #1, char 30: unterminated `s' command. Use the s command in sed to search and replace. shell by Coding Cobra on Mar 16 2020 Donate. May 21, 2019 · The cp command is the primary method for copying files and directories in Linux. The $ indicates the last line of a file. Example: To print 3rd line to 8th line. In the replacement, by having \1 only the group is retained, leaving out the remaining part. For more instructions, consult our beginner’s guide to the Linux command-line and other similar introductions to the If you need to find and replace the occurrence of a word, phrase, URL, or whatever, and it&#39;s in several documents, this can be a really tedious task. To replace the whole line using sed, it is needed to add wildcards (. # sed '1d' sed-demo. 3. To replace content in a file, you must search for the particular file string. Some are white, which indicates that they are enabled. May 02, 2015 · This is the fourth article of the "Super sed' Series", in which we will learn how to search for a pattern and replace it with other pattern in a file, using regular expressions. We will learn unix Mar 05, 2010 · How to replace line with another line in shell script: pramod. txt add character at The shell then runs the above command sed with the next arguments (assuming pattern=bert and file=text. File 1: hgacdavd sndm,ACNMSDC msgid "Rome" msgstr "" kgcksdcgfkdsb (4 Replies) Jan 13, 2018 · Use Stream EDitor (sed) as follows: sed -i 's/old-text/new-text/g' input. sed N; N; Now, we have a complete employee record in the pattern space. x+: Moreover, you also need to replace “file” with the name of the file where you want to make these replacements. In this case, if the newline is followed by a non-digit character, then it will replace it with a space (carrying over the matched number). *bytes. The first one liner numbers the lines, just like #8. For example, replace the line that matches "FOO  19 Feb 2017 Understand sed Linux command · Using multiple sed Linux commands in the command line · Reading commands from a file · Substituting flags · Replace characters · Limiting sed · Delet 22 Nov 2019 In contrast to grep , sed can substitute a line or multiple lines in a file and perform an in-place update of that file. txt file and renames the new file to my Passing filename from Command line and reading the File. == 2" < test line 1 new line 2 line 3 I want to find common line in two files and replace the next line of first file with the next line of second file. I haven’t run into any disk-space problems with -i ''. ubuntu command line replace word in files. See the ansible. Requirements: Access to the Linux command line and a file that contains Windows carriage returns. Recommended Reading: Sed Command in Unix · Replac I have a text file, where different forms of content exist, data or strings or symbols, i need to change a specific line (it's only sed. This is primarily useful when you want to change a single line in a file only. Some of them are descriptive lines in blue, uncommented with a # sign. For example, If the input file contains the following lines. Advanced Search and Replace. For example to replace /bin/bash with /usr/bin/zsh you would use. Majorly, the sed command will perform the multiple operations on the input file like text searching, deletion, find and replace the text data, data/text insertion, etc. sed - 3 Feb 2020 To replace a line in a text file by using line number we can use the following command in sed. com Apr 01, 2020 · Read: How to use the APT command on Ubuntu/Debian Linux systems. Or perl. g = global (i. 320002 56. The simplest sed invocation when substituting foo for bar is: $ sed 's/foo  18 Apr 2020 Linux has several different utilities that can perform string or text manipulation. # sed -e '/^two/s/one/replaced/g' /tmp/file. With GNU sed: sed -i '4d' . You can add a ^ at the beginning of the test to make sure you only get the lines that start with aaa= but that's up to you. */replacement-line/' file. txt. Cool Tip: Do not be a bore! Mar 05, 2018 · It’s important to remember that, unlike Windows, the Bash shell and its Linux-imitating environment are case-sensitive. Man Not the greatest, but this should work: sed -i 'Ns/. With sed , you can search, find and replace, insert, and delete words and lines. All the text files are located on In the Linux operating system, the sed command is used to filter the text data from the input file and transform the text data. Copy. This above command will replace the second… Replace whole lines matching pattern Permalink. txt): -i s,bert,Say hurrah to &: \0/, text. When [count] is given, replace in [count] lines, starting with the last line in [range]. txt” without a capital. In this case, we actually want to print non-matching lines, so we’ll use the -v option, which performs an inverted match: Jun 26, 2019 · This is what we call the PowerShell Read-Text File. #!/bin/bash # Check the command line argument valu 13 Jan 2018 sed find and replace text command: This guide explains how to use sed to find and replace text within a file on a Linux In this example only find word 'love' and replace it with 'sick' if line content a 14 Nov 2020 It can perform basic text manipulation on files and input streams such as pipelines. Delete last line or footer line or trailer line The following sed command is used to remove the footer line in a file. There are several easy ways to show them the door. txt . c\ text. So, we can search and replace using the substitution command: With new lines available in the pattern space, we can use the character as part of the regex. Hi All, As mentioned in the title I have two text files and I would like to replace line number 5 of file #1 with line number 4 of file #2 e. Method 1 – Using simple loop. 7/' file. Luckily, there is another way to achieve that. Jan 03, 2021 · The most general syntax for reading a file line-by-line is as follows: while IFS= read -r line; do printf '%s ' "$line" done < input_file. Aug 13, 2014 · To remove everything except the 1st n characters in every line : $ sed -r 's/ (. is this possible via sed? i badly need this. May 12, 2020 · Open the BASH configuration file for editing: sudo nano ~/. In this article, the method of writing a variable to a file in Bash using Ubuntu 20. Virtually all Linux distributions can use cp. The ‘sed’ command is used to replace any string in a file using a bash script. 1. /file Here, -i means edit the file inplace. txt > new-file. Use the below commands to append some PREFIX (some text or character) to the beginning of every line in a FILE: $ awk '{print "PREFIX"$0}' FILE – or – $ sed 's/^/PREFIX/' FILE. The first argument value is read by the variable $1, which will include the filename for reading. Use a combination of head and tail command in the following function the line number x: head -x file_name | tail +x You can replace x with the line number you want to display. Feb 17, 2021 · The file will be given as a command line argument when the script containing your command will run. The line number is always the same, so that can be a hard-coded variable. or the equivalent single-line version: while IFS= read -r line; do printf '%s ' "$line"; done < input_file. * -> matches any number of characters, and the first 3 characters matched are grouped using parantheses. The below sed command removes the first line in sed-demo. I have a situation where I want a bash script to replace an entire line in a file. Look no further! This blog post is for you. This will go through and find any lines that pass the aaa= test, which means that the line contains the letters aaa=. Scroll to the bottom of the configuration file. This is what I tried: sed s/maxmemory. You can use while read loop to read a file content line by line and store into a variable. It removes the need to run rm after doing an in-place replace. txt and replace by another line from b. Is it possible to specify by line number,on all files this string is exactly on 34th line. . Apr 21, 2011 · I have a similar issue, instead of replace the string with multiple lines, I need to replace a keyword in an xml file with the contents of a txt file containing multiple lines. Multiple Occurrence of same line. txt while IFS= read -r line do echo In the Sed Replacecommand, we can replace the string from the specific range of the input file/lines. In this (POSIX compliant) form of the command. txt by 1st line of b. txt) with the string " Good Morning " using a single terminal command. 4464002 3 319 286 369 46. (Note: Copy the command you entered on your linux system to answer all these questions. Here we will rediscover sed by example with equivalent commands and workflows to aid in day to day tasks. 2. If the whitespace can vary across files, or even within the same file or the same line /record from any file, one awk script will work w This module ensures a particular line is in a file, or replace an existing line using a back-referenced regular expression. the xml file has a keyowrd 'kw01', and i want to replace this string with the contents of a file named fatal_alerts. Feb 15, 2021 · H ow can I remove the ^M (carriage Return / line feed ) from text file using sed under UNIX or Linux operating systems? A newline is nothing but end of line (EOL). I'm not trying to replace some sub-string in that line, I just want to replace that line entirely with a new line. The s within the quot Use :1,10 w >> outfile to append lines 1 through 10 inclusive from the current file to outfile nondestructively. I've solved it by making a bash function (that can be reused in scripts). sed -i 's/\/bin\/bash/\/usr\/bin\/zsh/g' file. */$new_line/ if $. txt b. SED – Find and Replace a String in a File Use the following sed command to search each line of a FILE for a SEARCH_STRING and replace each matched line with REPLACEMENT_LINE : Aug 30, 2010 · A very useful function which is missing from the Windows library of command line tools is the ability to replace text in plain text files. Getting started Introduction. $ sed 's/Linux/Linux-Unix/' thegeekstuff. sed -i 's/original/new/g' file. It is a special character or sequence of characters signifying the end of a line of text and the start of a new line. Note: The search for "Unix" to replace with "Unix OS" should be case insensitive. Sep 15, 2011 · With a simple commandline (Bash command) can search and replace a word within a file (file can be. Similarly, in order to print lines starting from 5th up to last line, you would run-. 1. Use :s/foo/bar/ to replace the first occurrence of the word foo on the current line . followed by a newline) by replacing them with an empty string. Output: Jun 03, 2020 · To do in place replacement in the same file. $ sed 's/old_word/new_word/' /path/to/file. And so, does sed (sed -e 's/pattern/replacement/'). conf. The UNIX and Linux Forums. ' infile > tmpfile && mv tmpfile infile. The s is the substitute command of sed for find and replace. xxxxxxxxxx. This replaces the line in the original file. In the following example, the sed command removes the first line in a file. In other words, “File. This command can be used in various ways to replace the content of a file in bash. sed -i 's/^acl verizonfios. 24 Jul 2013 The sed stream editor is a non-interactive line editor that can perform powerful editing operations on text streams The sed command does not edit the source file by default, but you can change this behavior by passing 21 Jan 2015 One of them would be to replace the newline characters with the tag. txt This is line #3 This is line #4 This is line #5 This is line #6 This is line #7 This is line #8. The easier and much more readable option is to use another delimiter character. Say, you want to replace 'a' only in a specific line say 3rd line, not in the entire file: $ sed '3s/a/A/g' sample1. if the substitution was  2 Jun 2020 Linux Command Line: Find & Replace in Multiple Files · grep -rl: search recursively, and only print the files that contain “old_string” · xargs: take the output of the grep command and make it the input of Output file # should contain no more than one blank line between lines of text. txt werdfgdfgf werergfdgd sfdfgfgfgfgg i want to replace the 1st line of a. bashrc. For example, Windows-based text editors will have a special carriage return character (CR+LF) at the end of lines to denote a 18 Jan 2018 To perform a global search and replace in vi, use the search and replace command in command mode: The % is a shortcut that tells vi to search all lines of the file for search_string and change it to replacement_string 2014年12月24日 シェル, sed や awk で何でもできる, 面倒、冪等性の確保はユーザ次第 lineinfile: >- dest='/path/to/file/' state=present backrefs=yes regexp='^#?\s*ServerTokens' line='ServerTokens Prod' dest : 書き換える対象のファイル; regexp : 7 Mar 2013 If you dont wish to delete the lines from the original source file you can redirect the output of the sed command to another file. Then it uses two substitute commands  6 Mar 2020 (Note that sed counts lines continuously across all input files unless -i or -s options are specified. *) before and after a SEARCH_STRING. If no flags are specified the first match of line is replaced. org) Nov 01, 2020 · You can use the “stream editor for filtering and transforming text” sed. 6. Linux-Unix Sysadmin, Linux Scripting etc” only first Linux is replaced by Linux-Unix. Verify that file has been updated: more input. txt i want out put as (5 Replies) Replace a string AAA with another string BBB but there are lot of strings starting with AAA or ending in AAA ,and i want to replace only one on line 34 and keep others intact. Dec 14, 2012 · The sed syntax is as follows to match the line starting with “acl verizonfios” and replace the whole line: sed -i 's/find/replace/' file. Write new to th 26 Nov 2019 Related Articles · Replacing or substituting string : Sed command is mostly used to replace the text in a file. $ sed -n '3,8p' sedtest. The command string: s = the substitute command. Most people use the vertical bar (|) or colon (:) but you can use any other character: sed -i 's|/bin/bash|/usr/bin/zsh|g' file. Nov 09, 2009 · “c” command in sed is used to replace every line matches with the pattern or ranges with the new given line. It supports basic and extended regular expressions that Try sed "6s/old/new/g" file. ) 2. The sed is known as the stream editor. If you see what you want, add -i to change the file in place sed -i 's/#  9 Mar 2017 You have forgot -i. Consider a scenario where you have to find all occurrences of a certain text and then replace it with another in all the files. It only takes a minute to sign up. No need to use the sed or Perl. Example use cases. Sep 08, 2011 · $ new_line="new line 2" $ cat > test line 1 line 2 line 3 $ perl -pe "s/. replace all and not just the first occurrence) file. When [range] and [count] are omitted, replace in the current line only. 25 Jul 2020 sed s/ $// This will replace any single space at the end of the line with nothing. Also you will learn how to turn multiple lines of a file into one comma-separated line. txt,file3. 8. Change every occurrence of the word 'me' with 'you' but only at the end of a line. txt After deletion: 2 Unix Operating System 3 RHEL 4 Red Hat 5 Fedora 6 Arch Linux 7 CentOS 8 Debian 9 Ubuntu 10 openSUSE Nov 29, 2011 · my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line I also had this "problem" today: how to replace a block of text with the contents from another file. e. Modification should be made in place : $ sed -i 's/maxmemory. I have two files a. A zero-length extension means that the backup has the same name as the new file, so no new file is created. txt,file4. Depending on your environment and the tools that are available, you should be able to easily parse, find and replace any string in a text In these files long lines are split and marked with a soft line break consisting of a single end of a line, i. We came across a poorly coded PHP site which was using many  2006年2月27日 【 sed 】 文字列の置換,行の削除を行う また,sedコマンドに指定した ファイルの内容を処理する。 がある行に,「### Check Line ###」という 新しい行を追加する $ $ sed -e "/Error/i #### Check Line ###" source. txt” with a capital letter is different from “file. Feb 23, 2012 · The N command grabs the next line and adds it to the current one in the pattern buffer, separated by a newline. For changing the offsets in a patch file (line number of a block), this little snippet can be used: s/  18 Sep 2019 They have persevered in text files on Windows, but were never used on Linux systems. The syntax is like so: sed 'Nd' file Here N denotes Nth line in a file and d denotes delete a line. txt If file. txt,. So my sed -i "/aaa=/c\aaa=xxx" your_file_here. This Linux command creates a copy of the my_file. txt In the first command, the value given to the Record separator variable is space. txt $ cat new-file. wooledge. 723 (12 Replies) With bash string manipulation it’s easy to replace strings in your scripts. docx,. If you see what you want, add -i to change the file in place. We will explain commands with examples: Search and replace URLs in PHP files. txt cat input_file. My goal was to read the number in the file, and if the number is smaller than three add one to it, and if bigger reset the number to one. Databases - Oracle, mySQL etc. The syntax for deleting a line is: > sed 'Nd' file Here N indicates Nth line in a file. Or you could open the input file, open the output file, copy 68 lines fro 15 Jul 2009 Add a g at the end of the command to make it apply to all occurrences in the file. In this example, replace an IP address with 202. txt #add #character #at the #beginning of #each line replace # with ' ' ( space ) to add space in front of each line: $ sed 's/^/ /' file. Then you can target that newline in the s/// command. Replace a first line of the file. A {string} can be a literal string. txt file. If the file exists in the current location then while loop will read the file line by line like previous example and print the file content. So, let's say you want to display the 13th line of the file. The following command will replace a string string_to_replace with a new one new_string in a file named file_name. txt asfsdfsfsfdfsf asfwererfgdgf wrerwetretfdg b. We can replace the first occurrence of a pattern/string with a given string. Then it replaces the entire line with aaa=xxx. rpl string_to_replace new_string file_name. In previous articles on sed command, we've learned how to print lines in a file, delete lines from a file and insert/append lines to a file. g. Linux-Unix Sysadmin, Linux Scripting etc. Otherwise, it applies only to the first occurrence on each line. Apr 17, 2013 · $ sed 's/^/#/' file. Create a bash and add the following script which will pass filename from the command line and read the file line by line. sed '1d' file > newfile. com); Bash Guide (mywiki. txt add character at the beginning of each line Redirect the output produced by sed command to save it to a file: $ sed 's/^/ /' file. # sed -i ‘/two/cyour text’ /tmp/file. 3/' / etc / squid / squid. 5. so awk breaks the line from printing whenever it finds a space. 2. 04 is explained. Unix is an multi-user, multi-tasking system It is a command based operating system. > sed '$d' file linux unix fedora debian 3. It tells sed to find all occurrences of ‘old-text’ and replace with ‘new-text’ in a file named input. A {pattern} is one or more branches. Nov 14, 2020 · If you want to find and replace a string that contains the delimiter character (/) you’ll need to use the backslash (\) to escape the slash. ) first~step, This The syntax of the s command (which stands for "substitute") is: 's/regexp/replacemen Substitute 'Hello hello helLo HELLO' by 'Goodbye goodbye goodBye GOODBYE'. This is line one. */maxmemory 26gb/' /some/file/some/where. (sed,awk,perl,bash any solution is welcomed ) Case Ignored. · Replacing the nth occurrence of a pattern in a line : Use the /1, /2 etc flags to replace the 17 Jun 2020 “replace text in a file using sed command bash” Code Answer's. original = a regular expression describing the word to replace (or just the word itself) new = the text to replace it with. To do this without relying on any GNUisms such as -i without a parameter or c without a linebreak: sed '/TEXT_TO_BE_REPLACED/c\ This line is removed by the admin. Sed is not needed if doing simple replacements in a scripts, bash can do that out of the box. See full list on lostsaloon. sql, etc. txt I want to find a line in a. To save the changed text in a different file, d It is straightforward. This command eliminates the extra blank line appeared while running the first command. I want to replace the 5th line of multiple text files (file1. SED/AWK – Add to the Beginning. This tutorial contains two methods to read a file line by line using a shell script. Find and replace inside a text file using the "sed" command. Oct 28, 2006 · Thus, for example, the following would replace the letter c with the letter d in the text from file1 and write it to a file named file2: tr c d file1 > file2 If file2 does not already exist, it will be created automatically by the output redirection operator. Replace strings in files with bash string manipulation operators only. Bash string manipulation. A function like this can be used for a variety of practical tasks which many system admin’s perform, such as: Update configuration/INI files to replace UNC paths. To modify the file in place, use sed -i instead. The syntax is for bash version 4. file 1 wqwert 4. where N should be replaced by your target line number. Replace n th occurrence of word in a line The command we are going to execute will update the first occurrence of a word or a character in a line. First argument value is read by the variable $1 which will contain the filename for reading. In this file, you should see several different settings. Bash is a very interesting programming language. It has so many different aspects that can be explored for mastering oneself in Bash programming. If there were a variable within it which the shell or a script might recognize, it cannot replace it with a value. 100002 1 1 1 0. Apr 12, 2015 · Syntax: sed -n 'M,Np' FILE. Jun 25, 2020 · How to Replace All Occurrences of a Word in All Files in Linux Command Line. Share. txt,file2. 13 Apr 2017 You can specify line number in sed or NR (number of record) in awk. txt = the file name. d is the command to “delete the pattern space; immediately start next cycle”. This is line two. sed -i 's/# autologin=dgod/autologin=ubuntu/' /path/to/file. If you&#39;re running Mac OS X, Linux, or Nov 08, 2020 · grep is one of the most famous text-processing commands in the Linux operating system. builtin. */\1/' file Lin Sol Ubu Fed Red. In the second command, the value given to the RS variable is space or a new line character. sed 's/# autologin=dgod/autologin=ubuntu/' /path/to/file. # sed -e '/two$/s/one/replaced/g' /tmp/file. Explanation: We are replacing the string in-between line number 2 to 3, except that the string replace operation will not work. If the string has spaces in it, it should be embedded in quotation marks. Also, you need to replace LineNum with the line number of the particular line in which you want to make the replacement. txt my_file2. However, there is more to sed than replacing patterns in text files. doc,. txt apple orange bAnAnA pappaya '3s' denotes the substitution to be done is only for the 3rd line. Which stumps me because I don't know what that means. #!/bin/bash file=Sheetone. Or python. txt contains bert , the output will be: How to remove carriage returns from text files on Linux When carriage returns (also referred to as Ctrl+M's) get on your nerves, don't fret. Replacing text in a file with PowerShell is three-step process. Similarly if you want to match the line having the string “ three ” and replace the line with “ your text “. It allows us to search for patterns in input files and prints the lines that match. Are there any bash methods for doing this (or something simple that can be It is straightforward. 150002 45. Jun 26, 2019 · This is what we call the PowerShell Read-Text File. 3: sed -i 's/^acl verizonfios. > sed '1d' file unix fedora debian ubuntu 2. txt # Instruction Guides 1. Jan 15, 2014 · The -i '' (or, in Linux, just -i) tells sed to use a zero-length extension for the backup. Jan 29, 2021 · See “how to use sed to find and replace text in files in Linux / Unix shell” for more info. awk 'NR== 34 { sub("AAA", "BBB") }'. or use FNR (file number record) if you want to specify more than one file on the command l Replace a line in a text file automatically every week with Linux bash shell script. One file. . Syntax: #sed 'ADDRESS c\ new line' filename #sed '/PATTERN/ c\ new line' filename Sed Replace Example 1. Here's how to do that in Linux command line. */acl verizonfios src 4. For example: cp my_file. And sed comes handy when replacing strings in multiple files, using regex patterns if needed. The second one-liner uses the ' N' command to join the line containing the line number with the actual line. The below command replaces the first line of the file with the “The Geek Stuff”. Much shorter than Windows. Oct 28, 2020 · So for each line in [range] replace a match of {pattern} with {string}. Bash allows you to perform pattern replacement using variable expansion (${var/pattern/replacement}). */acl verizonfios src 202. < Back Page 12  9 Apr 2014 We use combination of grep, sed and xargs to achieve it mostly. It is a command-line interpreter as well. */maxmemory 26gb/ /etc/redis/redis. replace mod 4 May 2020 File has been transferred between systems of different types with different newline conventions. Sep 30, 2009 · In the example below, in the output line “1. As indicated in the comments, you need to provide "something" to your while loop. In this scenario, I have replaced FindWord sed and ReplaceWord with replace. The while construct is written in a way that will execute with a condition; if a file is given, it will proceed until the read exhausts. The basic format of the command is: cp [additional_option] source_file target_file. Nov 08, 2020 · Also, we have to increase the window size by two lines, so we can invoke the N command twice: $ sed -n '1,2p' emp. This tutorial will show you how to replace any string value from a file using a bash script. If you have multiple lines in a file containing that specific word or character, it will update the first occurrence in every line that matches. linux,bash,rhel. The d option in sed command is used to delete a line. Add the following line: PS1="MyTestPrompt> " Feb 19, 2017 · Suppose that you want to search for bash shell and replace it with csh shell in the /etc/passwd file using sed, well, you can do it easily: $ sed 's/\/bin\/bash/\/bin\/csh/' /etc/passwd Oh!! that looks terrible. Create a bash file and add the following script. This is a quick reference to getting started with Bash scripting.