473,379 Members | 1,201 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Inserting a character to a line

7
Hi,

How do I insert character (e.g. , or .) at certain positions in a line? For example I want to insert a period ( . ) after the first 4 characters of every each line in the file. I cannot do it in sed command. I'm playing with my script using perl command but to no avail. Please advice. Thanks in advance.

See below:

Input:
Expand|Select|Wrap|Line Numbers
  1. 12345
  2. 67890
  3. 23456
  4. 78901
  5. 34567
  6.  
Desired Output:
Expand|Select|Wrap|Line Numbers
  1. 1234.5
  2. 6789.0
  3. 2345.6
  4. 7890.1
  5. 3456.7
  6.  

Br,
Pete
Mar 22 '08 #1
3 1579
eWish
971 Expert 512MB
Here is one way you can do it.

Expand|Select|Wrap|Line Numbers
  1. my $string = 12345;
  2.    $string =~ s/^(\w{4})(.*)$/$1.$2/g;
  3.  
  4.    print $string;
Expand|Select|Wrap|Line Numbers
  1. #Output:
  2. 1234.5
--Kevin
Mar 22 '08 #2
pinpe
7
Hi,

I found my answer. This works on me:

Expand|Select|Wrap|Line Numbers
  1. $x =~ s/\A(....)/$1./;
  2.  
Tnx anyway. =)
Mar 22 '08 #3
KevinADC
4,059 Expert 2GB
Hi,

I found my answer. This works on me:

Expand|Select|Wrap|Line Numbers
  1. $x =~ s/\A(....)/$1./;
  2.  
Tnx anyway. =)

Where did you find it?
Mar 22 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Mechphisto | last post by:
I'm using a textarea to insert some notes into a database. It's inserting the complete result into the mySQL table including the linebreaks...and not as a visible symbol but an actual linebreak. If...
14
by: Miranda | last post by:
Hi, I have a ASP/vbscript program that generates random passwords. The problem is I need to insert those passwords into an Access database of 327 clients. I have the random password program...
1
by: Chris Sharman | last post by:
Writing a form, several questions have got a list of checkboxes, with associated descriptions (mostly one word), all on a line. Eg: Describe yourself: Fat Hairy Ugly Wears glasses. I want to...
1
by: helpSeekar | last post by:
What is the best character for inserting new line and which is accepted by most of the email clients. Right now I have \n mailMessage.Body = "Line 1 \n Line 2 \n Line 3"; This works good for...
2
by: Sam | last post by:
Hi, I have a file in which I want to insert a text in between say the a specific line. Basically, I want to read through the file and search for a particular line or character and then once I...
2
by: pramod | last post by:
Hi I am facing the problem while inserting the spanish characters in the DB2 UDB v8.2 database. We are pulling the data from SQL server through informatica and then pushing the same in the DB2...
15
by: Jaraba | last post by:
I am working in a project that I need to parse an arrayt an select records based upon the values parsed. I used the functions developed by Knut Stolze in his article 'Parsing Strings'. I am...
13
by: Vivek | last post by:
Hi, Is it possible to insert a '\0' value or for that matter any control character into a DB2 CHAR/VARCHAR field ? So if i do a 'select hex(column) from table' i should see a 0 in the output....
1
by: nmsreddi | last post by:
HI Friends i am using sqlserver2005 . I have column in my table with xml DataType .and while i am inserting data into it ,if '&' is there in data it is giving xml parser error as "XML...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.