Sponsored Content
Top Forums Shell Programming and Scripting Replacing specific entry using sed Post 302758343 by sunnyd1 on Saturday 19th of January 2013 03:39:45 AM
Old 01-19-2013
Linux sed fid and replace example

Hello Guys ,

I am new to shell scripting.

Below is what i have for you guys

file name employee.txt where I have a ^M at the end of the file , i can remove ^M usind sed

Solution 1Example 1 :
Code:
sed 's/ ^M/ /gi' employee.txt

Solution 2 Example 2 : :
Code:
1,$s/ ^M/ /g

But here is a catch on 1 thing ,where we need to apply the same concept to a entire folder where we have more than 50 file having the same problem of ^M to be removed , how can we do that ?

Problem :
Code:
ls -lrt /root/sunny1/
                              
                               
-rw-r--r-- 1 root root  3325 Dec  7  2011 install.log.syslog
-rw-r--r-- 1 root root 26725 Dec  7  2011 install.log
-rw------- 1 root root   949 Dec  7  2011 anaconda-ks.cfg
-rw-r--r-- 1 root root  1071 Oct 30 20:13 emplst.sh
drwxr-xr-x 2 root root  4096 Dec 10 20:51 Desktop
-rw-r--r-- 1 root root  1669 Jan 10 17:53 natasha_access.sh
-rw-r--r-- 1 root root   108 Jan 10 17:54 natasha_others
-rw-r--r-- 1 root root   109 Jan 10 17:56 last_sasha.sh
-rw-r--r-- 1 root root   140 Jan 10 18:02 emplsts_1_4.sh
drwxr-xr-x 2 root root  4096 Jan 10 18:33 redhat
-rw-r--r-- 1 root root   812 Jan 10 18:37 emplsts.sh
-rw-r--r-- 1 root root    59 Jan 14 18:52 emp1.sh
-rw-r--r-- 1 root root   549 Jan 19 12:55 employee.txt
-rw-r--r-- 1 root root   549 Jan 19 13:14 n_employee.txt
-rw-r--r-- 1 root root   507 Jan 19 13:20 f_employee.txt
[root@localhost ~]#


Last edited by Scrutinizer; 01-19-2013 at 05:18 AM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replacing specific lines in a file

Hi there I have a file which has the lines # Serial number for hostid EXP_SERIAL_="" These lines could be anywhere in the file as far as line numbers go, I would like replace these two lines with # Serial number for hostid $var1 EXP_SERIAL_$var1="$var2" Is there a quick and simple... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

2. Shell Programming and Scripting

SED Replacing all but one regex match on a line or specific matches

Hi, I'm attempting to rename some files that have spaces in them. Without linking sed commands together is it possible to replace the first three "." to " ". File.name.is.long.ext -> File name is long.ext I can get the desired effect with echo "File.name.is.long.ext" | sed 's/\./ /g;s/... (5 Replies)
Discussion started by: vectox
5 Replies

3. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies

4. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

5. Shell Programming and Scripting

Notification of the modification of a specific entry in a file

I need to get notification via email when the line containing a pattern is changed in a file. Not during the time any changes to file occurs. Ie if we reset a user password say example, demouser the hash in the line containing the word demouser in the file /etc/group changes. So when this change... (1 Reply)
Discussion started by: anil510
1 Replies

6. Shell Programming and Scripting

how to change specific value for a entry in the file

Hello All, can someone please suggest me a one line command to change a specific value that is associated to an entry in the file. for example #more schedulefile quartz.job.manual.bonus.schedule=0 0 9 ? * * # it should be changed to #more schedulefile... (5 Replies)
Discussion started by: bobby320
5 Replies

7. Shell Programming and Scripting

Replacing specific characters using sed

Hi, I have a text file which is output from a server and it lists all the files in a specific volume. However, the volume name appears as volume_name:. I would like to replace this with \\volume_name\volume_name. This is not a problem in itself as I can use sed to globally look for the... (8 Replies)
Discussion started by: vnayak
8 Replies

8. UNIX for Dummies Questions & Answers

Check for entry of specific pattern

Hey Guys and Gals, I am having trouble with what I thought shouldn't be hard.. In a script I am working on there is a need to enter a MAC address. MAC addresses are formatted ; XX:XX:XX:XX:XX:XX where X can be 0-9, a-f or A-F So in the sample script the query is something... (4 Replies)
Discussion started by: TAPE
4 Replies

9. Programming

PYTHON COPY Contents of file1 into a specific entry in file2

file1 cat dog fish file2 This is a bunch of lines <!-- INSERT ANIMALS HERE --> horse cheetah post results file2 This is a bunch of lines <!-- INSERT ANIMALS HERE --> cat dog fish horse (1 Reply)
Discussion started by: TY718
1 Replies

10. Shell Programming and Scripting

How to replace multiple "&nbsp;" entry with in <td> tag into single entry using sed?

I have the input file like this. Input file: 12.txt 1) There are one or more than one <tr> tags in same line. 2) Some tr tags may have one <td> or more tna one <td> tags within it. 3) Few <td> tags having "<td> &nbsp; </td>". Few having more than one "&nbsp;" entry in it. <tr> some td... (4 Replies)
Discussion started by: thomasraj87
4 Replies
SYSTEMD-VOLATILE-ROOT.SERVICE(8)			   systemd-volatile-root.service			  SYSTEMD-VOLATILE-ROOT.SERVICE(8)

NAME
systemd-volatile-root.service, systemd-volatile-root - Make the root file system volatile SYNOPSIS
systemd-volatile-root.service /lib/systemd/systemd-volatile-root DESCRIPTION
systemd-volatile-root.service is a service that replaces the root directory with a volatile memory file system ("tmpfs"), mounting the original (non-volatile) /usr inside it read-only. This way, vendor data from /usr is available as usual, but all configuration data in /etc, all state data in /var and all other resources stored directly under the root directory are reset on boot and lost at shutdown, enabling fully stateless systems. This service is only enabled if full volatile mode is selected, for example by specifying "systemd.volatile=yes" on the kernel command line. This service runs only in the initial RAM disk ("initrd"), before the system transitions to the host's root directory. Note that this service is not used if "systemd.volatile=state" is used, as in that mode the root directory is non-volatile. SEE ALSO
systemd(1), systemd-fstab-generator(8), kernel-command-line(7) systemd 237 SYSTEMD-VOLATILE-ROOT.SERVICE(8)
All times are GMT -4. The time now is 10:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy