How to use sed to look for the particular pattren and convert?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to use sed to look for the particular pattren and convert?
# 8  
Old 10-17-2013
That should be GNU sed, which works fine for me:
Code:
$ echo "raju    id      name    addr    10/16/2013      numberid        10/21/2013" | sed -e "s_\(..\)/\(..\)/\(....\)_\3-\1-\2_g"
raju    id      name    addr    2013-10-16      numberid        2013-10-21
$ sed --version | head -1
sed (GNU sed) 4.2.2

Note that sed writes to stdout - it won't affect file.tsv unless you explicitly tell it to with -i.
# 9  
Old 10-17-2013
i just tried this and worked but is there any better way i can work around


Code:
cat file.tsv | sed -e "s_\(..\)/\(.\)/\(....\)_\3-\1-\2_g" | sed -e "s_\(.\)/\(..\)/\(....\)_\3-\1-\2_g" > tmp.tsv

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove lines with Pattren Matching

Hi , I need to remove the lines that matches the pattern TABLEEXCLUDE *.AQ$_*_F ; * is wildcard, it can be any word. For example, I have following file: TABLEEXCLUDE THOT.AQ$_PT_ADDR_CLEANUP_QTAB2_F ; TABLEEXCLUDE THOT.AQ$_MICRO_SERVICE_QT_F ; TEST TABLEEXCLUDE... (1 Reply)
Discussion started by: rcc50886
1 Replies

2. Shell Programming and Scripting

Replace a string on specific lines which match a pattren

Hi Experts, I have a file which contains a pattern multiple times i.e. matchthispattren. If a line is matched with this pattern. I want a number in 1234567890 to 123456789 in that line. (Basically remove the last digit from that number. Please help. Thanks, Varun (1 Reply)
Discussion started by: varun22486
1 Replies

3. Shell Programming and Scripting

Convert string using sed

I have a couple structure definitions in my input code. For example: struct node { int val; struct node *next; }; or typedef struct { int numer; int denom; } Rational; I used the following line to convert them into one line and copy it twice. sed '/struct*{/{:l... (3 Replies)
Discussion started by: James Denton
3 Replies

4. UNIX for Dummies Questions & Answers

Get the previous word from the search pattren

Hi, How do i find the previous worlds from the searched pattrens? Input:- Create or replace procedure some tesx. search work is procedure(case insencitive). output:- Create or replace (8 Replies)
Discussion started by: manasa_vs
8 Replies

5. Shell Programming and Scripting

Convert sed to perl

Can anyone convert this from sed to perl: sed -n '/\var\/log/p' /etc/syslog.conf I think Ive looked at this to much....urgh.. Thanks Ben (5 Replies)
Discussion started by: bigben1220
5 Replies

6. Shell Programming and Scripting

find and replace pattren in file

Hi, I have the input file having data as follow: file1.txt 001 aaa_1:abcd 002 bbb_2:abcd I want output as, 001xabcd 002xabcd Here iam trying to replace "{1 space}{alphanumeric string with underscore}{:}" with characrter "x". I tried to achieve this using sed;but Iam not getting this... (5 Replies)
Discussion started by: gopalss
5 Replies

7. Shell Programming and Scripting

negate * with in pattren matching...

Hi Every one I have a file in the following manner... AAAAAA*PERFORM WRITEQ BBDFDD*PERFOMF WRITEQ FFFF *PERFOMF WRITEQ i want to find the lines which donot have * in 7th position.. I have tried this but some problem i think... grep '......*WRITEQ' INpFIle... any 6 chars not... (7 Replies)
Discussion started by: pbsrinivas
7 Replies

8. Shell Programming and Scripting

Problem with pattren Matching

I have a set of programs and there coressponding MAPSETs i tried grep on the all the programs and got the following out put from this i want to extract only the Program Name and Mapset name {i.e. the word in (' ') after MAPSET } There or some cases where u have no ( after MAPSET that need... (7 Replies)
Discussion started by: pbsrinivas
7 Replies

9. Shell Programming and Scripting

Search for a Pattren in the files.

Hi Guys, Can you please helpme with this: I would like to read all the files in a directory and need to search for a pattern, Can we use the grep at folder level. Thanks in advance. :) Sat. (2 Replies)
Discussion started by: sbasetty
2 Replies

10. Shell Programming and Scripting

How to convert grep to sed??

Hi, I am hing problem in grep.. So I need convert following code to sed based one.. grep -ie "error|exception" $LOG_DIR/Node$i\Log.txt >> $LOG_ERR_REP thats is I want to serach error and exception (ignore case) and write to other file . how to do? (5 Replies)
Discussion started by: redlotus72
5 Replies
Login or Register to Ask a Question