Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

spefic SED replace command

Original Message
Name: matt_gibson
Date: March 11, 2004 at 04:02:01 Pacific
Subject: spefic SED replace command
OS: UNIX
CPU/Ram: P3 128mb
Comment:
HI all

I need to replace the 23rd character on all lines beginning with P , with a blank character. Ive heard that the SED command is the best option, Can anybody help with the specific command line that would perform this operation.


Report Offensive Message For Removal


Response Number 1
Name: aigles
Date: March 11, 2004 at 06:03:16 Pacific
Subject: spefic SED replace command
Reply: (edit)
The solution with sed :

sed 's/^\(P.\{21\}\)./\1 /' input_file

Jean-Pierre.


Report Offensive Follow Up For Removal

Response Number 2
Name: nails
Date: March 11, 2004 at 10:54:41 Pacific
Subject: spefic SED replace command
Reply: (edit)
Jean-Pierre:

Good solution. Can you explain what you are doing for the benefit of us non-sed experts?

Thanks!

Nails


Report Offensive Follow Up For Removal

Response Number 3
Name: Dlonra
Date: March 11, 2004 at 17:57:52 Pacific
Subject: spefic SED replace command
Reply: (edit)
i'm like in awe of Jean-Pierre's solution. I had to
man, info and browse to understand it. i'd like to try to explain so I will really learn it.
The \ are shell escapes (except \1),so consider
sed 's/^(P.{21})./\1 /' input_file

(reg_exp) is a "grouping" of a regular expression pattern match and \1 is the value of match 1 - match 2 would be the 2nd set of parens, if there were any.

r{n} is an "interval expression", so the preceding regular expression r is repeated n times. In this case: .{21} is 21 of any character.

^P.{21} is the 1st 22 characters of lines beginning with P

Note the "." in })./\1 - this is the 23rd character- it is not in the () grouping.

So sed 's/^\(P.\{21\}\)./\1 /' input_file says replace the 1st 23 characters of lines that start "P" with the 1st 22 characters + space

very neat


Report Offensive Follow Up For Removal

Response Number 4
Name: aigles
Date: March 12, 2004 at 00:42:04 Pacific
Subject: spefic SED replace command
Reply: (edit)
Good explanation Dlonra.

sed is powerful, but very cryptic

Jean-Pierre.


Report Offensive Follow Up For Removal

Response Number 5
Name: Dlonra
Date: March 12, 2004 at 05:31:56 Pacific
Subject: spefic SED replace command
Reply: (edit)
correction:
in sed 's/^\(P.\{21\}\)./\1 /' input_file
\ are not "shell escapes", they are "sed escapes" so that sed will recognize them as special characters, e.g.:
echo ab{cd|sed 's/{//' -> abcd



Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: spefic SED replace command

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




Batch File- Current Date in Excel

how to setup call of duty to joytok

WindowsME / HotMail Problem

Corrupt memory

Convert fat32 to Ntfs


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC