problem using pattern with two digit in sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem using pattern with two digit in sed
# 1  
Old 10-16-2012
problem using pattern with two digit in sed

Hi,

I am trying to create a csv from a existing flat file.I am using the same data to create the csv file. But I have issues \10 columns onwards..


Code:
sed 's/^\(.\)\(............\)\(....\)\(........\)\(........\)\(........\)\(........\)\(...\)\(..\)\(..................\)\(.................\)\(...\)\(..\)\(..................\)\(..\)\(..\)\(.........\)\(.....\)\(...............\)\(..\)\(.................\)\(.................\)\(....................\)\(.......................\)\(.................\)\(.................\)\(..\)\(...............\)\(....................\)\(.\)\(....................\)\(................\)/\1,\2,\3,\4,\5,\6,\7,\8,\9,\10,\11,\12,\13,\14,\15,\16,\17,\18,\19,\20,\21,\22,\23,\24,\25,\26,\27,\28,\29,\30,\31,\32/g' $filename > output.csv

---------- Post updated at 11:33 AM ---------- Previous update was at 11:30 AM ----------

sorry about the formatting of the earlier code.
Code:
sed 's/^\(.\)\(............\)\(....\)\(........\)\(........\)\(........\)\(........\)\(...\)\(..\)\(..................\)/\1,\2,\3,\4,\5,\6,\7,\8,\9,\10/g' $filename > output.csv

# 2  
Old 10-16-2012
And, how do you think sed will interpret \10? As \1 (the first tagged group) followed by 0 or as \10 (the tenth tagged group)? Isn't there an ambiguity in this case?

But, sed will treat \10 and \1 (the first tagged group) followed 0. So, you can only tag 9 groups at the most.

Last edited by elixir_sinari; 10-16-2012 at 03:18 AM..
# 3  
Old 10-16-2012
thanks for the reply... is there any workaround for this issue...
# 4  
Old 10-16-2012
Though it is possible to deduce what you are trying to accomplish with the sed command, it would be better if you would post a sample of the input and the desired output.
# 5  
Old 10-16-2012
Quote:
Originally Posted by babom
is there any workaround for this issue...
Have you tried using awk..?

Please provide your input and desired output.
# 6  
Old 10-16-2012
If I understand right, you want to split long lines into fields a certain positions. If so, this might help

Code:
awk '
BEGIN { OFS="," } 
{
    print substr ($0, 1, 1),
          substr ($0, 2, 12),
          substr ($0, 14, 4),
          substr (...etc...);
}' $filename >output.csv

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

2. UNIX for Dummies Questions & Answers

sed command that deletes lines with 3-5 digit strings

Hello! My final exam in my Linux class is tomorrow, and I was just reviewing the grep and sed commands. I came across an example, by which I got stumped: it asks to provide a sed command that deletes all lines that contain exactly 3 to 5 digit strings, from a file. In this case, I created a... (3 Replies)
Discussion started by: kalpcalp
3 Replies

3. Shell Programming and Scripting

Problem with awk double digit fields

Hello Everyone, This 10th field is giving too much problem in AWK. How do i overcome ? pls suggest Thanks! cat /tmp/data_rank| awk 'BEGIN{ print "HT No" "," "Name" "," "Maths" "," "Physics" "," "Chemistry" "," "Total" "," "Gender" "," "University" "," "RANK Global" "," "Rank... (2 Replies)
Discussion started by: InduInduIndu
2 Replies

4. Shell Programming and Scripting

convert two digit in to single digit...

Hi Guys. My Input: ABCD 12 00 KL ABCD 12 08 DL ABCD 12 10 KK ABCD 12 04 LL ABCD 13 00 LP ABCD 13 1O LS Output: ABCD 12 0 KL ABCD 12 8 DL ABCD 12 10 KK ABCD 12 4 LL ABCD 13 0 LP (2 Replies)
Discussion started by: pareshkp
2 Replies

5. Shell Programming and Scripting

awk length of digit and print at most right digit

Have columns with digits and strings like: input.txt 3840 3841 3842 Dav Thun Tax Cahn 146; Dav. 3855 3853 3861 3862 Dav Thun Tax 2780 Karl VI., 3873 3872 3872 Dav Thun Tax 3894 3893 3897 3899 Dav Thun Tax 403; Thun 282. 3958 3959 3960 Dav Thun Tax 3972 3972 3972 3975 Dav Thun Tax... (8 Replies)
Discussion started by: sdf
8 Replies

6. Shell Programming and Scripting

sed pattern match problem

Hi all, hoping this is a simple one, tried looking but just can't see the solution As an example I've got a list of words that all start Ben..... Bendicks Benefiber Ben Benylin I need to only change the line Ben with Ben 10, ignoring the other lines. I tried the following ... (1 Reply)
Discussion started by: mrpugster
1 Replies

7. Shell Programming and Scripting

Place digit in front of the line searching pattern using sed command

hi All, i want to add the single digit front of the line in the report file and string compare with pattern file. patter file: pattern1.txt pattern num like 4 love 3 john 2 report file: report.txt i like very much but john is good boy i will love u so after execute... (9 Replies)
Discussion started by: krbala1985
9 Replies

8. Shell Programming and Scripting

sed - delete everything until the first digit comes up

Hi, I have a text file with content as follows: bla foo3200492 comment on this: 3900302 here comes the teddy 12 all I need is: 3200492 3900302 12 So I need the correct "sed" command to delete everything until the first number. I am not a regex expert, because I have to... (3 Replies)
Discussion started by: mcW
3 Replies

9. Shell Programming and Scripting

problem using sed for pattern matching

if abc.sh is 192.168.1.41 then the output that i get is v5c01 my code is sed 's/192.168.1.4/v5c0/g s/192.168.1.41/acc1/g' abc.sh 2>&1 | tee abc.sh i want to find 192.168.1.4 and replace it with v5c0 and find 192.168.1.41 and replace it with acc1 and i want to do it using sed (5 Replies)
Discussion started by: lassimanji
5 Replies

10. Shell Programming and Scripting

Replace one digit by two digit using sed

Folks, Is there a simple way to replace one digit by two digit using sed. Example, mydigit1918_2006_8_8_lag1.csv should be mydigit1918_2006_08_08_lag01.csv. I tried this way, but doesn't work. echo mydigit1989_2006_8_8_lag1.csv|sed 's/]/0]/' Thank you, (5 Replies)
Discussion started by: Jae
5 Replies
Login or Register to Ask a Question